today i just lay on my bed meditating programming stuff when an idea flows into my mind which i can’t solve with my own ability.Below is the Question.
I read a book that explain why EOF value is -1 and the explanation is as follow :
Why -1?Normally getchar() returns a value in the range 0 through 127 , because those are values corresponding to the standard character set , but it might return values from 0 through 255 if the system recognizes an extended character set . In either case , the value -1 does not correspond to any character , so it can be used to signal the end of file.
1.)It is weird for the statement above because i remember besides signed integer , signed character is also one type of variable exist in C , so that’s mean the value from -128 to 127 can be used.But why still the book mention -1 does not contradict to any character use for keyboard input??
The standard doesn’t say it’s
-1.It’s not a value that you can read from a file. It’s an “out of band” value that
getcand such can’t return in any case other than “end of file”.