1. Determine whether the file is successfully opened:
Whether the file is successfully opened or not. if (fp = fopen ("filename", "r") = NULL), the file fails to be opened.
2. Determine whether the file is ended:
To determine whether the ASCII file ends, fgetc () will return the end mark EOF (-1). Because the binary file data will show-1, you must use the feof (fp) function to determine whether the end mark is "-1", and feof (fp) = 1. So you can read a file while (! Feof (fp) {c = fgetc (in );
...}
3. ferror ()
When calling a variety of input and output functions, if there is a dislocation, in addition to reflecting the function return value, you can also use the ferror function to check. The call form is ferror (fp );
If the return value of ferror (fp) is 0, no error is returned. If an error occurs, a non-0 value is returned.
Each time an input/output function is called for a file, a new ferror function value is generated. Therefore, the return value of the ferror function should be checked immediately after an input/output function is called, otherwise, the information is lost.
When the fopen function is executed, the initial value of the ferror function is automatically set to 0;
4. clearerr ()
Clearerr (fp) sets the file error mark and end mark to 0. If an error occurs when an input/output function is called, The ferror function value is a non-0 value. After clearerr (fp) is called, the value of ferrer (fp) is changed to 0.
If an error mark is displayed, it is retained until the clearerr function or rewind function or any other input/output function is called for the same file.