Thank you , it is much better now,
Can I understand it this way?
1.EOF is a negative value returned only by a read function.
2.'\0' is set after the last character to mark the end of a string. so we use '\0' to determine
the end of a stream.
3.NULL is always recommanded to be used for pointers.
and NULL is always a return code of a function.
4. NULL isn't equal to '\0'.
is it right?
and more questions..
a pice of orginal text from "Why it's bad to use feof() to control a loop"
I am a little confusing about it,
most read functions will set EOF once they've read all the data, and then performed a final
read resulting in no data, only EOF
set EOF means set '/0'?
most read functions will set EOF once they've read all the data,
after haveing set EOF, why they read for a final one, to verify that all data was read?
and then performed a final read resulting in no data, only EOF
i = 0;
fgets(buf, sizeof(buf), fp);
printf ("Line %4d: %s", i, buf);
as mentioned above, it should set EOF right after getting all data,why here it goes
as the program goes through the loop to get the last line of data, fgets() works normally,
without setting EOF .
without setting EOF?
why now (set EOF)?
and we print out the data. The loop returns to the
top, and the call to feof() returns FALSE, and we start to go through the loop again. This
time, the fgets() sees and sets EOF
looking forward answers, thanks a lot
but thanks to our poor logic, we go on to
process the buffer anyway, without realising that its content is now undefined (most likely
untouched from the last loop).