The ferror () function in C
The int ferror function (FILE * stream) in Library C checks the error indicator for the given Stream.
The int ferror function (FILE * stream) in Library C checks the error indicator for the given Stream.
Declare the function ferror () in C
Below is the declaration for the ferror () function in C:
int ferror ( FILE * stream )
Parameters
stream - This is the pointer to a FILE object that identifies the Stream.
Returns the value
If the Error Indicator that binds to the Stream is set, the function returns a value other than zero. Otherwise, the function returns 0.
For example
The following C program illustrates the usage of the ferror () 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 opened in write only mode.
According to Tutorialspoint
Previous lesson: Function feof () in C
Next lesson: Function fflush () in C
Discover more
command in library C run program C parameter in CShare by
Samuel DanielYou should read it
- The sprintf () function in C
- Remove () function in C
- Function setbuf () in C
- Function fflush () in C
- The function fsetpos () in C
- The Quiet Details That Make a Sports Betting Platform Feel Reliable
- Instructions on creating toy set images with ChatGPT AI
- How are AI agents changing the journalism industry?
- Function fflush () in C
- The function fgetpos () in C
- Function fopen () in C