#include<stdio.h>
#include<conio.h>
void main()
{
char h[16], ch;
int i, c = 0;
clrscr();
printf("Enter string : ");
for(i = 0; ch != '\n'; i++)
{
ch = getchar();
h[i] = ch;
}
h[i] = '\0';
for(i = 0; h[i] != '\0'; i++)
{
if(h[i] == ' ')
{
c++;
while(h[i] == ' ')
i++;
}
}
printf("\nTotal words : %d", c + 1);
getch();
}
Also Read - BFS for Water Jug Problem in C
0 Comments