-
Strange EOF happenings
For some reason, whenever the program reads 1A in hex, 26 in dec it is reading it as EOF. I have it print out the character and, sure enough, it prints -1. I don't get it. Other programs are detecting EOF just fine. Here's the culprit code:
Code:
new_byte = fgetc(_source);
while(new_byte != EOF){
decompress(new_byte, bit);
for(i=0; i < (8/bit); i++){
fputc(_new_pixels[i], _dest);
}
printf("%d: ", j);
j++;
new_byte = fgetc(_source);
printf("%d\n", new_byte);
}
That is supposed to loop through over 8000 times, but it gets to byte number 206 and hit EOF. Here's the end of the output:
Code:
200: 0
201: 0
202: 15
203: 255
204: 139
205: 47
206: -1
Byte number 206 is 26, not -1
I changed byte 206 to 27, then it stopped on the next 26 later in the file.
Any ideas?
Thanks
-
Is new_byte an int like it should be?
-
-
Would something like this produce any clues?
Code:
new_byte = fgetc(_source);
while ( new_byte != EOF ) {
/*
decompress(new_byte, bit);
for(i=0; i < (8/bit); i++){
fputc(_new_pixels[i], _dest);
}
*/
printf("%d: ", j);
j++;
new_byte = fgetc(_source);
printf("%d\n", new_byte);
}
if(ferror(_source))
{
perror("_source");
}
if(feof(_source))
{
puts("Yup. EOF");
}
-
Code:
200: 0
201: 0
202: 15
203: 255
204: 139
205: 47
206: -1
Yup. EOF
That's interesting. By the way, the source file is 8196 bytes.
It only does that in Windows. I compile and run it on UNIX over ssh and it works fine. But it is going to be graded on a Windows machine. Maybe I'll just do it in UNIX and make a note of the problem.
Here's the end of execution in UNIX:
Code:
8192: 0
8193: 0
8194: 0
8195: 0
8196: 0
8197: -1
Yup. EOF
-
I don't seem to be all that helpful here. One more try: is _source opened in binary mode?
-
HOLY CRAP!! That worked.
Thanks a million Dave.