So I have been trying to write this program that opens a .txt file and then reads it and compares each word and special character to "and, but, ; " and counts the number of words typed. It has to recongnize that the end of the paper is when the user places a "#"
I have tried everything I know how to do and I still can't figure it out, so I have been trying to just print out what it is reading from the input buffer and then putting it in a loop and when it reaches a # it quits out of the loop but it turns into an infinite loop. Please help.
here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void input_paper()
{
char word[20];
char paper[8000];
cout<<"Please type out your paper and at the end of it put a # to show that your done"<<endl;
cin.get(paper, 8000,'#');
do
{
cin.get(word, 20, ' ');
cout<<word<<endl;
}while(word != "#");
}
Because you're reading into a buffer of 20 characters with "cin.get()" and not clearing it at any point in your loop, the char array 'word' will never be exactly equal to "#". I would suggest using the find() member function from the Strings library. http://www.cplusplus.com/reference/string/string/find/