Writing a paragraph, ignoring ENTER.

I am a beginner in C++.
I must write a program that takes in a paragraph (including spaces and enter and tab), and it must count the frequency of each letter, space, and enter (how many times the user has typed them).
So my two problems are:
1. The user should be able to continue writing even if he/she pressed enter.
2. The compiler does not ignore enter, but counts it and adds it to how many times it has been pressed.

Thank you so much,
Any help would be GREATLY appreciated.
Are you reading from a file or from keyboard input?
How would your program recognise the end of the paragraph?
Have you tried using getline ( http://www.cplusplus.com/reference/string/getline/ ) ?
Once you store the input, counting the characters isn't hard
How can i change the delimiting character for getline?
Pass it as third argument eg: getline ( cin, str, '#' ); ( If using it with cin, the user will always have to press enter after the delimiting character )
Ok Thanks alot.
But using getline, I can not use each character immediately when it is typed,right? (it is not like getchar())
For example, I used getline and stored "Hello, my name is Maya!" as a string.
I can do a loop and then see what each character is, right?
Thank you so much for your help Bazzy!
But using getline, I can not use each character immediately when it is typed,right? (it is not like getchar())
Using just standard stream you will always have to wait enter before reading anything
I can do a loop and then see what each character is, right?
Once you get a string you can have a loop in which you process each character in the string
Last edited on
In *nix, often a paragraph is a series of lines separated by a blank line --- or a series of sentences separated by an empty sentence. For example (where ■ represents '\n'):
This is sentence one.■
This is sentence two. And■
this is sentence three.■

Now is the start of a new■
paragraph. And this is the■
end.■

I wonder if that is what your professor expects you to parse?
Last edited on
Topic archived. No new replies allowed.