in c language i am using EOF .....why EOF IS -1 ? why not other value?
See Question&Answers more detail:osin c language i am using EOF .....why EOF IS -1 ? why not other value?
See Question&Answers more detail:osFrom Wikipedia:
The actual value of EOF is system-dependent (but is commonly -1, such as in glibc) and is unequal to any valid character code.
It can't be any value in 0 - 255 because these are valid values for characters on most systems. For example if EOF were 0 then you wouldn't be able to tell the difference between reading a 0 and reaching the end of file.
-1 is the obvious remaining choice.
You may also want to consider using feof
instead:
Since EOF is used to report both end of file and random errors, it's often better to use the feof function to check explicitly for end of file and ferror to check for errors.