1.

Write a function in C++ to count the words to and the present in a text file “POEM.TXT”.[Note. that the words “to’ and “the” are complete words.]

Answer»

void COUNT ()

{

 ifstream File;

 File. open (POEM.TXT);

 char Word[80] ;

 int Cl = 0, C2 = 0;

 while(!File.eof())

 {

 File>>Word;

 if (strcmp (Word, to) ==0)

 Cl++;

 else if (strcmp (Word, the) ==0)

 C2++;

 }

 cout<<”Count of -to- in file:" <<Cl;

 cout<<”Count of -the- in file:”<<C2;

 File.close(); //Ignore



Discussion

No Comment Found

Related InterviewSolutions