Hello LastSeen,
It is hard to find a starting place since there are so many problems. I will start with line 48, Not a good idea to check for end of file there because it may notwork the way you expect. EOF is set when you try to read past end of file and by the time you check for EOF you have already tried to process a bad read. A better way to write the while loop is:
while (std::getline(in, line))
this way when it tries to read past EOF it will fail and the while loop will become false and terminate.
At line 50 I would set a string stream equal to line and use the string stream in the current while loop at line 50 with the code:
1 2 3 4
|
while (getline(ss, words, ' '))
{
counter++;
}
|
this way the string stream ss works just like reading the file, but you can reuse the ss and you will not have to back up the file pointer to reread something you have already read.
In line 56 you could pass the array and the string stream or the variable line to the function, the int i and char ch are not needed. I have not tried it yet, but the variable line might be a better choice in order to access each character in the string.
In line 15 the int i and char ch are not needed there and the reference if pointless because you are not changing these values. The char ch variable should be defined inside the function process because that is where it is need.. And the for loops anywhere should be written as
for (int i = 0; i < Alph_Count; i++)
. This way you do not have to get the definition of i from main. If the function parameters only contain the array and string stream you will not have to deal with moving the file pointer back to reread what you have already read.
Line 22 do not test for EOF there. Line 24 I would replace this with
1 2 3 4 5
|
for (int i = 0; i < line.length(), i++)
{
if (toupper(line[i]) >= 'a' && toupper(line[i]) <= 'z')
stats[line[i] - 'A'].count++;
}
|
Then the check for lower case letters will not be needed.
The final loop looks like it should work, I have not tested it yet. Work on these changes and let us know what problems you have or any questions you might have.
Hope that helps,
Andy