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

Derivatives stock list at NSE

Complete FNO stock list at NSE. ABB India Ltd ACC Ltd APL Apollo Tubes Ltd AU Small Finance Bank Ltd Aarti Industries Ltd Abbott India Ltd A...