-
EOF file pointer
Hi,
I´d like to know if while I´m reading a file I can check wether the next cycle in my While is going to be EOF... I need this because I´m reading 13 byte chunck at a time. sorry for my english. thank you in advance.
code:
Code:
while (ch=fgetc(fp))!=EOF)
//check the buffer
buffer++;
....
if ((buffer<12) && (###)
### here I want to check if current position + 1 == EOF
any answer is welcome
-
Well if you're reading from a file, you can start by using fseek() and ftell() to work out where the end of the file is.
You can then count how many bytes you read, and thus work out whether you've reached the end or not.
Or you could do
Code:
char buff[13];
while ( fread( buff, 13, 1, fp ) == 1 ) {
// do something with 13 bytes of data
}
If there is less than 13 bytes remaining at the end of the file, then fread() won't return them.
-
Thank you very much! I´ll try that way. ;)