Okay. I am done. (It is 02:16 AM here, tomorrow I have important exams so I won't advance it much). But what I have for you is extremely fast, memory-sparing and short algorithm for counting characters without any limits.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) // <-- No main input parameters will be used
{
FILE* fp;
char fileName[128], lookupTable[128] = {0};
int currentChar;
printf("Enter file name (Appending the extension (.txt)): "); scanf("%s", fileName);
if(!(fp = fopen(fileName, "r")))
{
printf("Error opening file: %s\n", fileName);
return EXIT_FAILURE;
}
while((currentChar = fgetc(fp)) != EOF)
{
lookupTable[currentChar]++;
}
for(currentChar = 0; currentChar != 128; currentChar++)
{
printf("%c\t:\t%i\n", currentChar, lookupTable[currentChar]);
}
fclose(fp);
return EXIT_SUCCESS;
}
It lists each character and how many occurrences are in the text file specified. Since you have the base algorithm, you can play a bit with it and easily restrict it and fit it on your taste.
@anduril462 Too late.. But thats the reason why I didn't do his homework. Just provided him a good example of how he can do that. From now on, he needs to fit it on the way he like it. I won't even explain the code.