Fgetc does not identify EOF

The program below works fine on various versions of Solaris / Linux, but not on AIX. However, if I replace while(c!=EOF) with while(c!=0xff) on AIX, it works completely fine.

Any thoughts? I checked the fgetc man page on AIX and should return an EOF constant!


 #include <stdio.h> #include<unistd.h> #include <string.h> int main() { char c; FILE *fp; fp = fopen("a.txt", "r"); c=fgetc(fp); while(c!=EOF) { c=fgetc(fp); printf("%d",c); } fclose(fp); return 0; } 
+6
c types eof aix fgetc
source share
1 answer

Return value fgetc int not char . Therefore change

 char c; 

to

 int c; 
+15
source share

All Articles