Make Your Search Easy ! :) Use me

Friday, February 17, 2017

Counting number of occurrences of a word ("is") in a file :-

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<string.h>

void main()
 {
    ifstream fin("msg.txt");
      char word[5];
      int count=0;
      cout<<"CONTENTS OF FILE IS :- \n";
      while(fin)
       {
            fin>>word;
          cout<<word<<" ";
          if(!strcmpi(word,"is"))
             {
                count++;
               }
         }
      cout<<"\nNumber of appearance of \"is\" = "<<count;
      getch();
   }

No comments:

Post a Comment