a problem when using int feof(FILE *fp);

C

Chad

In the code that Jens has presented he use fgetc in a loop to read from
a file and output characters until EOF is encountered. The code in the
first pair of #if 0... #endif are simply alternate forms of the same
read loop using instead of fgetc, fscanf and fread. If they had been
compiled (i.e., if the #if 0... #endif were absent), they too would be
executed after the first loop has run it's course. They would most
probably immediately return end-of-file since after the first loop fp
is already read.

This is a case where the #if 0 and #endif are not critical to
correctness, but generally code that has been preprocessed or commented
out should not be compiled without a careful review.


Okay, I think this is the part that is not *clicking*. I don't see
when the code would skip over fgetc() and use something like fread()
instead.
 
S

santosh

Chad said:
Okay, I think this is the part that is not *clicking*. I don't see
when the code would skip over fgetc() and use something like fread()
instead.

It won't "skip over" anything. If you want to use fscanf, you block out
the loops using fgetc and fread. If you want to use fread, you block
out the code using fgetc and fscanf. If you want to use fgetc, you
block out code that uses fscanf and fread, as in the version posted by
Jens. Simple, isn't it?
 
C

Chad

It won't "skip over" anything. If you want to use fscanf, you block out
the loops using fgetc and fread. If you want to use fread, you block
out the code using fgetc and fscanf. If you want to use fgetc, you
block out code that uses fscanf and fread, as in the version posted by
Jens. Simple, isn't it?


Yes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top