So i need to decrypt a Caesar Cypher for my CS class from a text file that is encrypted. I have to find the most common letter within the file and find the distance from the character e or E. My first though was just to use
1 2 3 4 5 6
while (inFile.peek() != EOF)
{
getline(inFile, line);
cout << line << endl;
char analyze[] = line;
}
Sorry if the code doesn't make sense but what i was hoping to accomplish was to have the array put each character from the line into it's appropriate array slot. I could then use the array to find the most common letter occurring in that line. However, I receive an error every time saying there is no conversion from string to char or char to int. I think that I can use something like char array[] = "Hello" to make a character array of 6 slots but can I do the same with what I used above? I am completely lost and I could really use some help
hi black! what i would do is read in each line (using getline(inFile, line) as the condition for the while loop) and then use a for loop to iterate through the line. then what character it hits it adds one to its equivalent number in the alphabet held in an array (ie: int AlphaCount[26] = {0}; so if it sees an f then f's position in the alphabet - 1 is upped by one in the array. then just find which in the array has the largest value.
Thank you so much for your reply! so you say that i would read in the one line, and then do a for loop checking each letter in the line for matches? I am confused as to how to check each char in the line :( also the document has upper and lowercase letters in it. i know about the functions tolower() and toupper() for changing an alphabetic character from lowercase to uppercase and vice-versa. Also, would the function isalpha() be of any use to me here so that I am not trying to change commas or periods in the line?