Problems with my c letter count program
Hi, I have been working on a program in c that takes an input and counts how many of each letter there are and then lists them in the form eg:
A: 56
B: 68
C: 43 etc etc
Im haveing problems geting it to spit out the right results and is me all kinds of funny numbers and symbols and at the end saying segmentation fault(core dumped) heres my code, if you can see what i need to change please can you help. thankyou
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main() {
int LetterCounts[26] = {0};
int c = 0, j = 0;
while ((c = getchar()) != EOF) {
if (isalpha(c)) {
c = toupper(c);
}
LetterCounts[c-'A']++;
}
for(j = 'A'; j < 'Z'; j++) {
printf(": %d\n", LetterCounts[j+'A'], LetterCounts[j]);
}
return EXIT_SUCCESS;
}