#include <stdio.h>
//feof,ferror,clearerr函数
int main()
{
FILE *fp;
int nRet;
fp = fopen("a.c","w+");
if(fp == NULL)
{
printf("open file failed!\n");
return -1;
}
fputc('a',fp);
rewind(fp);
nRet = fgetc(fp);
printf("nRet is %c\n",nRet);//打印读取字符
nRet = fgetc(fp);
printf("nRet is %d\n",nRet);//打印返回值
printf("feof is %d,ferror is %d\n",feof(fp),ferror(fp));//判断文件是否已结束/错误
clearerr(fp);//清除流错误
printf("feof is %d,ferror is %d\n",feof(fp),ferror(fp));
fclose(fp);
return 0;
}