6

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

Any thoughts? I checked the fgetc man page on AIX, and it should return the 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; } 
1
  • It seems that AIX has chars that are unsigned Commented May 25, 2018 at 7:46

1 Answer 1

17

The return value of fgetc is int not char. So change

char c; 

to

int c; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.