James Bailie escribió:
fgetc() returns an int so that EOF may be distinguished from valid
return values.  Valid values are 8-bit values.  EOF is a 32-bit value.

EOF is a 32-bit two's-complement -1 (0xffffffff), and -1 input is 8-bit
two's-complement -1 (0xff).  When fgetc() casts this to an int, it
becomes 0x000000ff, or 255, and thus the two values may be distinguished
from each other.

I haven't looked at your code, but you are probably comparing EOF with
the value returned by fgetc() after it has been cast to a char.  EOF is
getting cast to a char implicitly in the comparison, so the comparison
becomes a comparison between 0xff and 0xff.  You need to test the int
returned by fgetc() for EOF before assigning it to a char.
Thanks, I've found all the pieces of the puzzle from the three comments and it works now.

--
Gabor Kovesdan
FreeBSD Volunteer

EMAIL: ga...@freebsd.org .:|:. ga...@kovesdan.org
WEB:   http://people.FreeBSD.org/~gabor .:|:. http://kovesdan.org

_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

Reply via email to