Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fgetc does not identify EOF [duplicate]

Tags:

c

types

aix

eof

fgetc

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;
}
like image 977
raxit Avatar asked Oct 20 '10 11:10

raxit


1 Answers

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

char c;

to

int c;
like image 125
codaddict Avatar answered Sep 29 '22 23:09

codaddict