Problem with loop stopping at wrong time
Hello again.
I have created the following program to count the number of times each letter of the alphabet appears in a textfile. It works properly, unless there are no occerences of a certain character. Instead of just returning the value 0, it stops and any other letter in the alphabet after it that is in the file dosnt get counted\printed and I can't figure out why. Any ideas??
Code:
#include <stdio.h>
#include <stdlib.h>
char inputArray[1024], inFile[128];
FILE *in;
int charCount, countArray[26] = {0}, aRep, *ptr;
float lettotal, percentage;
void main()
{
printf("\nInput name of plaintext file, including full path:\n");
gets(inFile);
if ((in = fopen(inFile, "r")) == NULL)
{
printf("\nCould not open file to be converted\n");
exit(8);
}
while (aRep != EOF)
{
aRep = fgetc(in);
if (aRep >= 97 && aRep <= 122)
{
aRep = aRep - 32;
}
if (aRep >= 65 && aRep <= 90)
{
inputArray[charCount] = aRep;
charCount++;
}
}
inputArray[charCount] = '\0';
charCount = 0;
for (charCount = 0; charCount != '\0'; charCount++)
{
aRep = inputArray[charCount] - 65;
countArray[aRep] = countArray[aRep] + 1;
}
countArray[charCount] = '\0';
charCount = 0;
printf("Number of each letter in file:\n");
for (charCount = 0; countArray[charCount] != '\0'; charCount++)
{
aRep = charCount + 65;
printf("%c:%d\t", aRep, countArray[charCount]);
}
}
Thanks
-Chris
P.S. I know there are a couple of unused variables and a pointer, they are for somthing else it needs to do later once this part works =)