clearerr_s

重設資料流錯誤指標。這是一個版本的 clearerr 中所述的安全性增強功能與安全性功能,則在 CRT 中

errno_t clearerr_s(
   FILE *stream 
);

參數

  • stream
    指標FILE結構

傳回值

如果成功 ;,零 EINVAL如果stream為 NULL。

備註

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

如果stream為 NULL,無效的參數處理常式會叫用,如所述參數驗證。如果執行,則允許繼續執行,這個函式會將errno到EINVAL ,並傳回EINVAL。

需求

常式

所需的標頭

clearerr_s

<stdio.h>

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

範例

// crt_clearerr_s.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;
   errno_t err;

   // Create an error by writing to standard input.
   putc( 'c', stdin );
   if( ferror( stdin ) )
   {
      perror( "Write error" );
      err = clearerr_s( stdin );
      if (err != 0)
      {
         abort();
      }
   }

   // See if read causes an error.
   printf( "Will input cause an error? " );
   c = getc( stdin );
   if( ferror( stdin ) )
   {
      perror( "Read error" );
      err = clearerr_s( stdin );
      if (err != 0)
      {
         abort();
      }
   }
}
  n
  n
寫入時發生錯誤: 不正確的檔案描述項
輸入將會導致錯誤吗? n

.NET Framework 對等用法

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

請參閱

參考

錯誤處理 (CRT)

資料流 I/O

clearerr

_eof

feof

ferror

perror _wperror