Hi all,
I'm trying to help out my friend. She is trying to write a word count program in C++. Basically, she is reading from a text file and then counting how many times certain words (the, an, a, of, etc...) are used. She is currently assigning the text file into one big string.
I'm quite rusty with my C++. But I told her that she would need a WHILE loop with an EOF condition. I am not quite seeing the part where each words are parsed. I'm picturing that within the WHILE loop I need another WHILE loop with an EOL (end of line) condition and inside it I would assign each line to one string. Then, using string functions in C++ that I don't remember I can use the space character as my delimiter and parse my the words. I would loop in the WHILE with EOL condition subtracting that word from my string. If a word matches the word lists that I have, then a counter assigned to it would be incremented.
Is my logic right? Is there a way to optimize this? Someone told me to use a HASH table, but I'm not familiar with it. Is there an example program that I can view?
Thanks!
I'm trying to help out my friend. She is trying to write a word count program in C++. Basically, she is reading from a text file and then counting how many times certain words (the, an, a, of, etc...) are used. She is currently assigning the text file into one big string.
I'm quite rusty with my C++. But I told her that she would need a WHILE loop with an EOF condition. I am not quite seeing the part where each words are parsed. I'm picturing that within the WHILE loop I need another WHILE loop with an EOL (end of line) condition and inside it I would assign each line to one string. Then, using string functions in C++ that I don't remember I can use the space character as my delimiter and parse my the words. I would loop in the WHILE with EOL condition subtracting that word from my string. If a word matches the word lists that I have, then a counter assigned to it would be incremented.
Is my logic right? Is there a way to optimize this? Someone told me to use a HASH table, but I'm not familiar with it. Is there an example program that I can view?
Thanks!