Detailed Print – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
siteicon
Solved Problem#CPP#5890

Problem Statement - 04A

Write function definition for SUCCESS () in C++ to read the content of a text file STORY.TXT count the presence of world STORY and display the number of occurrence of this word.
Note :
-The word STORY should be an independent word
-Ignore type cases (i.e. lower/upper case)
Example: If the content of the file Story.TXT is as follows:

Success shows others that we can do it. 
It is possible to achieve success with hard work. Lot of money does not mean SUCCESS.

The function SUCCESS () should display the following:

3

Solution

Click to open popup

Solved Problem Understanding

void SUCCESS()
{
int count=0;
ifstream f(“STORY.TXT”);
char s[20];
while (!f.eof())
{
f>>s;
if(strcmpi(s,”STORY”)==0)
//OR if(strcmpi(s,”SUCCESS”)==0)
count++;
}
cout<<count;
f.close();
}