Wednesday 6 September 2017

C-Program to count number of words in a sentence



#include<stdio.h>
#include<string.h>

int main()
{
    int i,word=1;
    char str[100];
    printf("Enter a string\n");
    gets(str);
    for(i=0;i<strlen(str);i++)
    {
        if(str[i]==' ')
        {
            word++;
        }
    }
    printf("%d\n",word);
  return 0;
}

No comments:

Post a Comment