I'm trying to count the frequency of letters inside a string array and setting the frequencies to an array of size of the entire alphabet. I hope I've designed the way so upper/lower cases don't matter. After this, I want to set the letter of highest frequency as the 'e' of that alphabet (since e occurs with the most frequency in many languages) and find the difference between the most frequent letter and e. It seems to make sense in my mental walkthrough but my compiler for some reason gives me breakpoint and doesn't allow me to check it at all, so I'm not sure what's wrong. So please forgive me for not posting an SSCCE. Thanks in advance for helping!
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int alpharay[26];
for (int i = 0; i < 26; i++)
{
alpharay[i] = 0;
}
ifstream input;
cout << "File name (.txt): ";
string fileName;
cin >> fileName;
input.open(fileName.c_str());
while (!input.eof())
{
string newLine;
getline (input, newLine);
for (int i = 0; i < newLine.length(); i++)
{
if (isalpha(newLine[i]))
{
int index;
if (isupper(newLine[i]))
{
index = newLine[i] - 'A';
alpharay[index]++;
}
else if (islower (newLine[i]))
{
index = newLine[i] - 'a';
alpharay[index]++;
}
}
}
}
//To find the largest value in array
int largest = 0;
char popular;
for (int i = 0; i < 26; i++)
{
if (alpharay[i]>=largest)
{
largest = alpharay[i];
popular = 'a' + i;
}
}
//To find the size of the shift
int shift = popular - 'e';
cout << "Shift size: " << shift << endl;
return 0;
}