Skip to content

Latest commit

 

History

History
137 lines (117 loc) · 3.47 KB

File metadata and controls

137 lines (117 loc) · 3.47 KB
title clearerr | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-standard-libraries
ms.tgt_pltfrm
ms.topic article
apiname
clearerr
apilocation
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
apitype DLLExport
f1_keywords
clearerr
dev_langs
C++
helpviewer_keywords
error indicator for streams
resetting stream error indicator
clearerr function
ms.assetid a9711cd4-3335-43d4-a018-87bbac5b3bac
caps.latest.revision 21
author corob-msft
ms.author corob
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

clearerr

Resets the error indicator for a stream. A more secure version of this function is available; see clearerr_s.

Syntax

void clearerr(  
   FILE *stream   
);  

Parameters

stream
Pointer to FILE structure.

Remarks

The clearerr function resets the error indicator and end-of-file indicator for stream. 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.

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. For more information on errno and error codes, see errno Constants.

A more secure version of this function is available; see clearerr_s.

Requirements

Routine Required header
clearerr <stdio.h>

For additional compatibility information, see Compatibility in the Introduction.

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" );  
}  
  
n  
  
  
      nWrite error: No error  
Will input cause an error? n  
No read error  

See Also

Error Handling
Stream I/O
_eof
feof
ferror
perror, _wperror