I am reading a byte byte file, I need to determine if eof has reached.
The feof () function does not work because "eof is set only when a read request is made for a byte that does not exist." So, I can have my own custom check_eof, for example:
if ( fread(&byte,sizeof(byte),1,fp) != 1) {
if(feof(fp))
return true;
}
return false;
But the problem is that if eof is not reached, my file pointer moves forward bytes. Therefore, the solution may be to use ftell(), and then fseek()to get the right position.
Another solution might be to buffer the byte in front in some temporary storage.
Any better solutions?
source
share