Hi,
I need help trying to do the following:
Basically, I am trying to count the occurrences of each character in a text file. I'm reading in line by line, and then in each line, analyzing character by character.
I'm maintaining an array of the counts.
The conversion of the character to ascii and then ascii to its proper index is working, but when I try to print out the contents of the array, I'm getting ridiculous numbers. Here's my code:
Code:
int autoGuess() {
int r, x, size, asciiEquiv;
int charCount[26];
for (r = 0; r < lineCount ; r ++) /* Outer Loop Reads Line By Line */
{
for (size = 0; size < sizeof(stringArray[r]); size++) { /*Inner Loop Reads character by character */
if (isalpha((stringArray[r][size])))
{
asciiEquiv = (int)stringArray[r][size];
/* printf("%d " , asciiEquiv); It is converting the characters to their respective ASCII codes properly */
place = asciiEquiv - 97;
/* printf("%d ", place); Converting to Index Properly */
charCount[place]++;
printf("%d " , charCount[place]); // Something happens here
}
}
}
for (x = 0; x < 26 ; x ++) {
//printf("%d ", charCount[x]);
getchar();
}
}
Thanks!