well it seems that you did not get the problem 100%. It says...
QUOTE
Problem: Read in a file. Count the number of occurences of each letter in file. Ignore newline, tab, integers, etc...
I can't use any helper functions or anything of the sort.
Example:
Here is the file. how many.
h - 2
e - 4
r - 1
, etc..
and now you have a structure associated with it.
Please understand that you need to show count for every character from a - z so you will need 26 structure variables to store their counts.
so you can have a structure like
CODE
struct counts
{
char ch;
int count;
};
now have an array of structures like
CODE
counts char_struct[26] //as there are 26 alphabets.
and initialise ch of this structures in a for loop to get
CODE
char_struct[0].ch='a'; char_struct[1].ch='b'; //and so on till z.
now get the character from file one by one till file ends and have a switch like
[ use while loop on "infile". Something like : while(!infile.eof()) ]
CODE
switch(ch)
{
case 'a' :
case 'A' : char_struct[0].count++; break;
case 'b' :
case 'B' : char_struct[1].count++; break;
//like this till z
}
try this and tell me whether you got it...
ya and you have to put code in between the tags like
[code ]
//code goes here
[/code ]
then it shows it like [I just removed that extra space there]
CODE
//code goes here