A line of English text will be given, where words are separated by one
of the following symbols:
' ', '\t', '.', ',' and ';'
You have to count the number of words
#include<stdio.h>
int main(){
int foundLetter = 0,count= -1,c;
c = getchar();
while ( c != EOF )
{
c = getchar();
if(c == ' '||c =='.'||c =='\t'||c ==';'||c ==',')
{foundLetter=0;}
else
{
if (foundLetter == 0)
count++;
foundLetter = 1;
}
}
printf("%d",count);
}
in the sentence.
int main(){
int foundLetter = 0,count= -1,c;
c = getchar();
while ( c != EOF )
{
c = getchar();
if(c == ' '||c =='.'||c =='\t'||c ==';'||c ==',')
{foundLetter=0;}
else
{
if (foundLetter == 0)
count++;
foundLetter = 1;
}
}
printf("%d",count);
}
Thanks
Happy Computing !
No comments:
Post a Comment