clearerrclearerr

重置流的错误指示符。Resets the error indicator for a stream. 提供此函数的一个更安全的版本;请参阅 clearerr_sA more secure version of this function is available; see clearerr_s.

语法Syntax

void clearerr(
   FILE *stream
);

参数Parameters

streamstream
指向文件结构的指针。Pointer to FILE structure.

备注Remarks

Clearerr函数将重置的错误指示符和文件尾指示符。The clearerr function resets the error indicator and end-of-file indicator for stream. 错误指示器不会自动清除;设置指定流的错误指示符后,在调用clearerrfseekfsetpos倒带之前,对该流执行的操作将继续返回错误值。Error indicators are not automatically cleared; once the error indicator for a specified stream is set, operations on that stream continue to return an error value until clearerr, fseek, fsetpos, or rewind is called.

如果streamNULL,则会调用无效参数处理程序,如参数验证中所述。If stream is NULL, the invalid parameter handler is invoked, as described in Parameter Validation. 如果允许执行继续,则此函数会将errno设置为EINVAL ,并返回。If execution is allowed to continue, this function sets errno to EINVAL and returns. 有关errno和错误代码的详细信息,请参阅errno 常量For more information on errno and error codes, see errno Constants.

提供此函数的一个更安全的版本;请参阅 clearerr_sA more secure version of this function is available; see clearerr_s.

要求Requirements

例程所返回的值Routine 必需的标头Required header
clearerrclearerr <stdio.h><stdio.h>

有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.

示例Example

// 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" );
}

输入Input

n

OutputOutput

Write error: No error
Will input cause an error? n
No read error

请参阅See also

错误处理Error Handling
流 I/OStream I/O
_eof_eof
feoffeof
ferrorferror
perror、_wperrorperror, _wperror