still trying to read the file and find the most frequent letter.
but somethings terribly wrong. I hope someone can help me see what i am doing so wrong.
what i have so far:
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void charactercount ( char ch , int list[]);
void copytext ( ifstream &intext, char &ch, int list[]);
void writetotal (int list[]);
int main()
{
int lettercount[26];
char ch;
char reply;
ifstream infile;
string myfile;
ifstream inputFile;
inputFile.open ("encrypted.txt");
if(!inputFile)
{
cerr << "Can't open input file " << myfile << endl;
cout << "Press enter to continue...";
exit(1);
}
inputFile.get(ch);
while (inputFile)
{
copytext(inputFile, ch, lettercount);
inputFile.get(ch);
}
writetotal(lettercount);
inputFile.close();
cin >> reply;
return 0;
}
void charactercount( char ch , int list[])
{
int index;
ch = toupper(ch);
index = static_cast<int>(ch) - static_cast<int>('A');
if ( 0 <= index && index < 26)
list[index]++;
}
void copytext ( ifstream &intext, char &ch, int list[])
{
while ( ch != '\n')
{
charactercount(ch, list);
intext.get(ch);
}
}
void writetotal (int list[])
{
int index;
for ( index = 0; index < 26; index++)
cout << static_cast<char>(index + static_cast<int>('A')) << " Count = " << list[index] << endl;
}
output:
Code:
A Count = -858992861
B Count = -858993305
C Count = -858993454
D Count = -858992948
E Count = -858992917
F Count = -858992749
G Count = -858993236
H Count = -858993382
I Count = -858993337
J Count = -858993450
K Count = -858993363
L Count = -858993456
M Count = -858992890
N Count = -858993355
O Count = -858993243
P Count = -858993182
Q Count = -858992487
R Count = -858993265
S Count = -858993303
T Count = -858993052
U Count = -858992940
V Count = -858993425
W Count = -858993438
X Count = -858993169
Y Count = -858993277
Z Count = -858992891