1.

Write a function in C++ to print the count of the word is an independent word in a text file DIALOGUE.TXT.For example, if the content of the file DIALOGUE.TXT is: This is his book. Is this good?Then the output of the program should be 2.

Answer»

void wordcount

{

ifstream fin("DIALOGUE.TXT");

char word[10];

int wc=0;

while(!fin.eof())

{  fin>>word;

if((strcmp(word,"Is")==0)||(strcmp(word,"is")==0))

wc++;

}

cout<<wc;

fin.close();

}



Discussion

No Comment Found

Related InterviewSolutions