1/*
2 * C Program to Count Number of Words in a given Text Or Sentence
3 */
4#include <stdio.h>
5#include <string.h>
6
7void main()
8{
9 char s[200];
10 int count = 0, i;
11
12 printf("Enter the string:\n");
13 scanf("%[^\n]s", s);
14 for (i = 0;s[i] != '\0';i++)
15 {
16 if (s[i] == ' ' && s[i+1] != ' ')
17 count++;
18 }
19 printf("Number of words in given string are: %d\n", count + 1);
20}