Q : Write a ‘C’ program to count number of words in a string.
Solution :
#include<stdio.h>
void main()
{
char
str[50];
int i,w;
printf("Enter
a string>> ");
gets(str);
for(i=0,w=1;str[i]!='\0';i++)
{
if(str[i]==' ')
w++;
}
printf("\n\tNo
of word is %d",w);
}
Download Source Code
No comments:
Post a Comment