a.c
#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 runs perfectly but the while
loop only runs once.
The output looks like
rewind
? – Inequitablewhile
loop ran only once? – Davedavedarewind(file)
after while loop will do the job – Quinquennium