fgetc
reads a character from a file at a time, and returns the character as type of int
. If the file ends, then fgetc
returns EOF
("probably" (int)(-1)
). However, I have seen this so frequently:
char ch;
while ((ch = fgetc(fp)) != EOF) { /* Do something. */ }
|<-- PARN -->|
This is what I concern:
fgetc
readsOxFF
and returns0x000000FF
.0xFF
is assigned toch
. (type casting fromint
tochar
)- If
PARN
is type ofchar
, then it will be promoted to0xFFFFFFFF
. - Break out of the while loop because
PARN == EOF
. (stop reading from the file)
How can we tell reading OxFF
and returning EOF
apart?