Skip to content

Latest commit

 

History

History
113 lines (87 loc) · 2.93 KB

clearerr-s.md

File metadata and controls

113 lines (87 loc) · 2.93 KB
description title ms.date api_name api_location api_type topic_type f1_keywords helpviewer_keywords ms.assetid
Learn more about: clearerr_s
clearerr_s
4/2/2020
clearerr_s
_o_clearerr_s
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-stdio-l1-1-0.dll
DLLExport
apiref
clearerr_s
error indicator for streams
resetting stream error indicator
clearerr_s function
b74d014d-b7a8-494a-a330-e5ffd5614772

clearerr_s

Resets the error indicator for a stream. This function is a version of clearerr with security enhancements as described in Security features in the CRT.

Syntax

errno_t clearerr_s(
   FILE *stream
);

Parameters

stream
Pointer to FILE structure

Return value

Zero if successful; EINVAL if stream is NULL.

Remarks

The clearerr_s function resets the error indicator and end-of-file indicator for stream. Error indicators aren't automatically cleared; once the error indicator for a specified stream is set, operations on that stream continue to return an error value until clearerr_s, clearerr, fseek, fsetpos, or rewind is called.

If stream is NULL, the invalid parameter handler is invoked, as described in Parameter validation. If execution is allowed to continue, this function sets errno to EINVAL and returns EINVAL.

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.

Requirements

Routine Required header
clearerr_s <stdio.h>

For more compatibility information, see Compatibility.

Example

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

Input

n

Output

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

See also

Error handling
Stream I/O
clearerr
_eof
feof
ferror
perror, _wperror