Share via


clearerr_s

重設資料流的錯誤指標。 此函式是 的版本 clearerr ,具有 CRT 中安全性功能中所述 的安全性增強功能。

語法

errno_t clearerr_s(
   FILE *stream
);

參數

stream
FILE 結構的指標

傳回值

如果成功,則為零; EINVAL 如果 為 ,則 streamNULL

備註

clearerr_s 函式會重設 stream 的錯誤指標和檔案結尾指標。 不會自動清除錯誤指標;設定指定資料流程的錯誤指標之後,該資料流程上的作業會繼續傳回錯誤值,直到 clearerr_s 呼叫 、 fsetposclearerrfseek 、 或 rewind 為止。

如果 streamNULL ,則會叫用不正確參數處理常式,如參數驗證 中所述 。 若允許繼續執行,此函式會將 errno 設為 EINVAL,並傳回 EINVAL

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

常式 必要的標頭
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

輸出

Write error: Bad file descriptor
Will input cause an error? n

另請參閱

錯誤處理
資料流 I/O
clearerr
_eof
feof
ferror
perror, _wperror