/* int ferror ( FILE * stream ); Checks if the error indicator associated with stream is set, returning a value different from zero if it is. 当文件以r打开,或者磁盘满时会返回非0. */ #include <stdio.h> int main () { FILE * pFile; pFile=fopen("myfile.txt","r"); if (pFile==NULL) perror ("Error opening file"); else { fputc ('x',pFile); if (ferror (pFile)) /* 这里如果没有这个判断,程序正常结束,不会报错. */ printf ("Error Writing to myfile.txt\n"); fclose (pFile); } return 0; } /* 函数
输出信息到stderror. */void perror ( const char * str );