counting letters

How would I count the number of times a certain letter is used in a document using c++?

loop through it and use an if statement to compare it to a letter then if it is the letter add one to the count.
If you need counts for several letters it would be good to use array of counters:
1) initialize array A to zeroes
2) read next letter C
3) convert C to integer value X (not pretty tough in C, ha-ha)
4) increment A[X] by one
5) if there are more letters, go to 2
6) at the end run through A and for each A[I] convert I back to character C and print out how many times this C was counted (that is A[I])

Here you can practice this task:
http://codeabbey.com/index/task_view/vowel-count
And here is a simplified version, with numbers instead of letters:
http://codeabbey.com/index/task_view/array-counters
Topic archived. No new replies allowed.