About "feof ()"

xiaoxiao2021-03-06  48

Look at the following program, how can you output twice? If feof () is fine, please tell me why? #include

Main () {file * fp; int N = 74, k; printf ("/ n"); fp = fopen ("joseph.b", "wb "); fwrite (& N, 2, 1, fp); fclose (fp); fp = fopen ("joseph.b", "rb "); while (! feof (fp)) {FREAD (& K, 2, 1, FP); Printf ("% d", k);} Fclose (fp);}

When the file is opened, the file pointer points to 0 does not point to the first character. When the FREAD points points to the position it just read, there is no pointing to the file, so FeOF is running back to 0, and when FREAD is again executed again Shift, Feof will return 1.

This should be like this! The explanation of MSDN is that the FREAD returns 0 is an error, and this error can be used to determine using FeOF or FERROR. If FREAD is not wrong, it will not be at the end, it will read it again!

转载请注明原文地址:https://www.9cbs.com/read-115877.html

New Post(0)