C program to calculate total number of Words.

#include<stdio.h>
#include<string.h>
#define MAX 100
int main()
{
    char str[MAX];
    int i=0,word=1;
    printf("Enter a string:");
    gets(str);
    while(str[i]!='\0')
    {
     if(str[i]==' ' ||str[i]=='\n' || str[i]=='\t')
      {
         word++;
      }
      i++;
    }
    printf("The number of words in String are:%d",word);
    return 0;
}

**** INPUT && OUTPUT ****



Post a Comment

0 Comments