Here is source code of the C Program to Count the Number of Words in a given text Or Sentence. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C Program to Count Number of Words in a given Text Or Sentence
int count = 0, i;
printf("enter the string\n");
for (i = 0;s[i] != '\0';i++)
if (s[i] == ' ')
printf("number of words in given string are: %d\n", count + 1);
$ cc string2.c $ a.out enter the string welcome to sanfoundry's c-programming class! number of words in given string are: 5
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms