Saturday 11 November 2017

C Program to Count Number of Words in a given Text or Sentence


Code:

#include
#include

void 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] == ' ')
            count++;    
    }
    printf("number of words in given string are: %d\n", count + 1);
}

Output:

enter the string
welcome to executecodes c-programming class!
number of words in given string are: 5


More C programs:


















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...