Is !feof supposed to work?

This is a discussion on Is !feof supposed to work? within the C Programming forums, part of the General Programming Boards category; Hi,
I've made a little program which gives me the frequency of every byte inside a file, but for some ...

Is !feof supposed to work?

Hi,
I've made a little program which gives me the frequency of every byte inside a file, but for some reason in a file which has no 0xFF (255) bytes, I still get a "phantom" one. I am using a "while (!feof(fp))" loop and reading the bytes using getc. Do I have !feof in the wrong place for it to work?

The reason you are getting the 0xFF byte is that an EOF condition may occur after an attempt to read a byte from the file.
You need to also add a check after the read to ensure that it actually read the byte.