Table of Contents
This guide covers the function clearerr ()() in c with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.
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
FAQ
What should I check before following these steps?
Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.
Why might the process not work?
Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.
Can I undo the changes if necessary?
That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.
Reader Comments 0
Sign in with email or Google to join the discussion.