重設資料流的錯誤指標。 此函式是的版本clearerr,具有CRT中安全性功能中所述的安全性增強功能。
語法
errno_t clearerr_s(
FILE *stream
);
參數
stream
FILE 結構的指標
傳回值
如果成功,則為零; EINVAL 如果 為 ,則 stream 為 NULL。
備註
clearerr_s 函式會重設 stream 的錯誤指標和檔案結尾指標。 不會自動清除錯誤指標;設定指定數據流的錯誤指標之後,該數據流上的作業會繼續傳回錯誤值,直到clearerr_s呼叫、fseekfsetposclearerr 、 或 rewind 為止。
如果 stream 為 NULL,將會叫用無效參數處理常式,如參數驗證 (部分機器翻譯) 中所述。 若允許繼續執行,此函式會將 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