Saved Bookmarks
| 1. |
Write a function in C++ to print the count of the word as an independent word in a text file STORY.TXT. For example, if the content of the file STORY.TXT is:There was a monkey in the zoo.The monkey was very naughty.Then the output of the program should be 2. |
|
Answer» void wordcount() { ifstream fil("STORY.TXT"); char word[30]; //assuming longest word can be 29 characters long int count = 0; while(!fil.eof()) { cin>>word; if((strcmp("the",word)==0) && (strcmp("The",word)==0)); count++; } fil.close(); cout<<count; } |
|