Counting Letters in a Text File

Hi all!

I'm really stuck on this problem... I have to open a file stream "text" and count each time a letter occurs and print it out. For example, the file "Hello World" would have 1 H; 1 E; 3 L; etc etc.

Any ideas where to start?
open a file: http://www.cplusplus.com/reference/iostream/fstream/ and http://www.cplusplus.com/doc/tutorial/files/

read from a file: (the fstream link above) in particular get() and/or getline() function
first you must have one ifstream variable, then one array of integer, index and one char variable,
you will take char by char from the file, then when you find char for example big letters (in ASCII: from 65 to 91 i think they was) you reached your array of integer like this. array[91-(int)a] which will put the counter in array from 0 to 25 depends of character order in alphabet. if it is char 'a' your counter will be at position 'array[0]'. I think this will help you.
Topic archived. No new replies allowed.