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

Sacred Thought

28 April 2024 Today I am going to explain verse 31 - 38 chapter two for you all. There is no opportunity better than a righteous war (सत्य औ...