C File =>
/* Write a program to count the total number of words in a string. */
#include<stdio.h>
#include<string.h>
int main()
{
int i,wcnt=0;;
char s[50];
printf("\n Enter your String : ");
scanf("%[^\n]s",s);
printf("\n string = %s",s);
for(i=0;s[i]!='\0';i++)
{
if(s[i]==' ' && s[i+1]!=' ')
wcnt++;
}
printf("\n Word Count = %d",wcnt+1);
return 0;
}
Comments
Post a Comment
Please do not enter any spam link in message.