ac
#include <stdio.h> int main(int argc, char *argv[]) { int i, counter=0; char c; FILE *file=fopen("a.txt","r"); for (i = 0x41 ; i < 0x45; i++) { printf("%c(%x) ",i ,i); while ((c = fgetc(file)) != EOF) { if (i == (char) c) counter++; } printf("%d\n", counter); counter=0; } fclose(file); return 0; }
a.txt
AAABBBAAA
I donβt understand why the for loop works fine, but the while runs only once.
The output looks like

source share