Feof (FP) has two return values: if the file ends, the feof (FP) value of the function is 1; otherwise, it is 0. EOF is the end mark of a file.In a text fileThe data is stored in the form of the characters ASC ⅱ code value. The range of ASC ⅱ code is 0 to 255, and-1 is not possible,Therefore, you can useEOF indicates the end of a file. When the data is stored in a binary file, the value-1 is displayed. Therefore, the EOFEnd flag of a binary file. To solve this problem,Asci c provides a feof function to determine whether a file is terminated. The feof function can be used to determine both binary files and text files. The "feof ()" function in the "c" language is totally different from the "EOF ()" function in the database. The "EOF ()" function in the database reads the position of the current pointer. The "feof ()" function in the "c" language returns the last "read operation content ". After many years of mixing "location and content", the concept is similar. So what is the difference between location and content? For example, some people say that "You go to the last train box" is the location. If we say "please keep walking backward and touch the rails to the end", this is the content. That is to say, "One more section" will be judged by the content ". This is completely dependent on "while (! When the feof (FP) {...} file is copied, the target document will always be "more" than the source document. The "C" file cannot be fully dependent on "while (! Feof (FP) {...} "judgment. Difference from EOF In stdio. H, you can see the following definitions: # Define EOF (-1) # DEFINE _ ioeof 0x0010 # Define feof (_ Stream)(_ Stream)-> _ flag & _ ioeof) Int C; While (! Feof (FP )) { C = fgetc (FP ); Printf ("% x \ n", C ); } One more outputFF, because after reading the last character, FP-> flag is still not set to _ ioeofTherefore, feof () still does not detect the end of the file. Feof () cannot detect the end of a file until fgetc () is called again. In this way, one more-1 (FF) is output ). The correct statement should be: Int C; C = fgetc (FP ); While (! Feof (FP )) { Printf ("% x \ n", C ); C = fgetc (FP ); } Can feof () be replaced by EOF? No. When fgetc returns-1,There are two cases: Reading the end of a file or reading an error. Therefore, we cannot be sure that the file has ended., Because it may be a read error! In this case, we need feof ().
|