[C] 检测流上的错误 →→→→→进入此内容的聊天室

来自 , 2019-11-16, 写在 C, 查看 96 次.
URL http://www.code666.cn/view/4ae67a7d
  1. #include <stdio.h>
  2.  
  3. int main ( void )
  4. {
  5.         FILE *stream;
  6.  
  7.         /* open a file for writing */
  8.         stream = fopen ( "DUMMY.FIL", "w" );
  9.  
  10.         /* force an error condition by attempting to read */
  11.         ( void ) getc ( stream );
  12.  
  13.         if ( ferror ( stream ) )  /* test for an error on the stream */
  14.         {
  15.                 /* display an error message */
  16.                 printf ( "Error reading from DUMMY.FIL\n" );
  17.  
  18.                 /* reset the error and EOF indicators */
  19.                 clearerr ( stream );
  20.         }
  21.  
  22.         fclose ( stream );
  23.         return 0;
  24. }

回复 "检测流上的错误"

这儿你可以回复上面这条便签

captcha