Trying to write a program where a user types a sentence in and the program returns a table indicating the number of occurences of each letter of the alpabet in that sentence. Any suggestions??
Printable View
Trying to write a program where a user types a sentence in and the program returns a table indicating the number of occurences of each letter of the alpabet in that sentence. Any suggestions??
Yeah, this code makes so:
http://www.cpp-home.com/code.php?33_1
It just reads a file but not sentence, but you can get the algorithm...
Is there any other way to do this?
declare an array of 256 int called symbols
intialize each element of symbols to zero
declare an int called index
obtain input
determine length of input
use loop to cast each char in input to an int and assign that value to index
increment symbols[index] by 1;
determine which values of ACSII (or whatever char set your compiler uses) correspond to the letters you wish to report on. Use a loop to display the letter corresponding the the element number as a charactrer and the value stored at the element is the number of times the character was found in whatever the input was.