3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

The solution is pretty easy if you think about it. Every character in the English alphabet, and other characters too, have a numeric value between 0 and 255. To see what they are just google for "ascii chart". Given that, create an int array of 255 elements and initialize all of them to 0. Then read the file one character at a time, using the character as the index into the array. For example

int array[255] = {0};

array['A']++;

In the above the 65th element of the array will be incremented because the decimal value for the letter 'A' is 65. Instead of hardcoding the letter 'A' you would use the variable that you used to read the character in the file.

When you are done reading the file, all the consonants will already be in sorted order, so all you have to do is print them out. Loop through the array looking for array elements that are greater than 0 and are consonants.

Program done.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.