165. C Program to Find Number of Words in a Given Line.
How does this program work?
- This Program is used to find number of words in a given line.
Here is the code
#include <string.h>
int main()
{
char s[200];
int count = 0, i;
printf("Enter the string:\n");
scanf("%[^\n]s", s);
for (i = 0;s[i] != '\0';i++)
{
if (s[i] == ' ' && s[i+1] != ' ')
count++;
}
printf("Number of words in given string are: %d\n", count + 1);
return 0;
}