clearerr

重設資料流錯誤指標。更安全版本之這個函式是可使用; see clearerr_s.

void clearerr(
   FILE *stream 
);

參數

  • stream
    指標FILE結構。

備註

clearerr函式會重設錯誤指標和檔案結尾指標就會stream。不會自動清除錯誤指標。 一旦設定為指定的資料流錯誤指標,該資料流上的作業就會繼續傳回錯誤值,直到clearerr, fseek, fsetpos,或rewind呼叫。

如果stream是NULL,不正確的參數處理常式會叫用,如所述參數驗證。如果執行,則允許繼續執行,這個函式會將errno到EINVAL ,並傳回。如需有關errno ,錯誤代碼,請參閱 errno 常數

更安全版本之這個函式是可使用; 請參閱 clearerr_s

需求

常式

所需的標頭

clearerr

<stdio.h>

其他的相容性資訊,請參閱相容性在簡介中。

範例

// crt_clearerr.c
// This program creates an error
// on the standard input stream, then clears
// it so that future reads won't fail.

#include <stdio.h>

int main( void )
{
   int c;
   // Create an error by writing to standard input.
   putc( 'c', stdin );
   if( ferror( stdin ) )
   {
      perror( "Write error" );
      clearerr( stdin );
   }

   // See if read causes an error.
   printf( "Will input cause an error? " );
   c = getc( stdin );
   if( ferror( stdin ) )
   {
      perror( "Read error" );
      clearerr( stdin );
   }
   else
      printf( "No read error\n" );
}
  n
  n
寫入時發生錯誤: 沒有錯誤
輸入將會導致錯誤吗? n
無法讀取錯誤

.NET Framework 對等用法

不適用。 若要呼叫標準的 c 函式,使用PInvoke。 如需詳細資訊,請參閱平台叫用範例

請參閱

參考

錯誤處理 (CRT)

資料流 I/O

_eof

feof

ferror

perror _wperror