The function clearerr () in C
Void function clearerr (FILE * stream) in Library C deletes end-of-file and error indicator for the given Stream.
Void function clearerr (FILE * stream) in Library C deletes end-of-file and error indicator for the given Stream.
Declare the function clearerr () in C
Here is the declaration for the clearerr () function in C:
void clearerr ( FILE * stream )
Parameters
stream - This is the pointer to a FILE object that identifies the Stream.
Returns the value
This function should fail and not set the external variable errno but in case it detects that its parameters are not a valid stream, it must return -1 and set errno to EBADF.
For example
The following C program illustrates the usage of the clearerr () function in C:
#include int main () { FILE * fp ; char c ; fp = fopen ( "baitapc.txt" , "w" ); c = fgetc ( fp ); if ( ferror ( fp ) ) { printf ( "Da xay ra loi trong khi doc baitapc.txtn" ); } clearerr ( fp ); if ( ferror ( fp ) ) { printf ( "Da xay ra loi trong khi doc baitapc.txtn" ); } fclose ( fp ); return ( 0 ); }
Suppose we have a text file named baitapc.txt , which is an empty file. Compiling and running this program will produce the following results. Because we try to read a file that has been opened in write-only mode (write only).
According to Tutorialspoint
Previous lesson: The function fclose () in C
Next lesson: Function feof () in C
You should read it
- Function setbuf () in C
- Function fwrite () in C
- The function fread () in C
- The function perror () in C
- Function tmpfile () in C
- Function vfprintf () in C
- The function setvbuf () in C
- Function fprintf () in C
- The sprintf () function in C
- Remove () function in C
- The getchar () function in C
- The function fclose () in C
Maybe you are interested
The whole scene of meteorites hitting the Earth during the past 33 years, why can't we feel it? The most beautiful meteor shower of the year and amazing astronomical phenomena in August NASA reveals its latest snapshot of the Martian surface with a resolution of 1.8 billion pixels Is Proxima b our 'neighbor' planet? Why have scientists found Proxima b - '2nd Earth' until now? The mystery of the numbers of Proxima b: The 'Second Earth' on the planet may exist life