Sunday, February 25, 2018

C program : To count the number of words in the sentence.

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
in the sentence.
 
 
 #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);
}
 
Thanks
Happy Computing !

No comments:

Post a Comment

Python Certification

 Python course from codebasics  https://codebasics.io/courses/python-beginner-to-advanced?utm_source=infocard&utm_medium=yt&utm_camp...