Data File Handling - Solution (SD/4/B/168)

Write a function CountHisHer() in C++ which reads the contents of a text file "NOTES.TXT" and counts the words His and Her (not case sensitive).

Solution:

Data File Handling - Text File (SD/4/B/168)


void CountHisHer()
{
ifstream file("NOTES.TXT",ios::in);
int his=0, her=0;
char word[80];
while(!fin.eof())
{
fin.getline(word,80,' ');
if(strcmpi(word,"his")==0)
his++;
else if(strcmpi(word,"her")==0)
her++;
}
fin.close();
cout<<"Count of His : "<< his <<endl;
cout<<"Count of Her : "<< her <<endl;
}



No comments

Post your comments

Powered by Blogger.