In this program every character counts as one -- even spaces, tabs, and end-of-line. You need to
find the correct way to get one char from an fstream to make the algorithm work.
Algorithm to count characters input
(
- declare and set a counter to zero.
- declare a variable to hold a char
- WHILE the program can get a char from the input stream DO
(
- add 1 to the counter
)
- END WHILE
- Output a report to the user with the value of the counter
)
Hint -- KEEP IT SIMPLE
As far as this program is concerned, a word is a string with no spaces, tabs, or end of line characters.
So "1+2" and "mouchoir" are both words.
Copy the character counter program into a new file and modify it to read and count
C++ strings rather than chars. String input reads one "word" at a time.
Strong hint: do NOT use the old C char*/cstring library.
Second Hint -- Start by copying looking at the algorithm for the previous problem...
Each line -- even a blank line, counts as a line. Again by selecting the right input function
you can make this program by copying the previous one and making some small changes.