1.

Write a function in C++ to count the no of “Me” or “My” words present in a text file “DIARY.TXT”. If the file “DIARY.TXT” content is as follows:My first book was Me and My family. It gave me chance to be known the world. The output of the function should be Count of Me/My in file : 4

Answer»

void COUNT( ) {

 ifstream Fil("DIARY. TXT");

 char STR[10];

 int count = 0;

 while(!Fil.eof( ))

 {

 Fil>>STR;

 if(strcmp(STR,"Me")==0||strcmp(STR,"My")==0)

 count++;

 }

 Cout<<"Count of Me/My in file :"<<count<<end1;

 Fil.close( ); //Ignore

}



Discussion

No Comment Found

Related InterviewSolutions