fgetc does not identify EOF [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 17:18:40

问题


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:


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

char c;

to

int c;


来源:https://stackoverflow.com/questions/3977223/fgetc-does-not-identify-eof

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!