feof problem

Hi.

Firstly im using VC++ 6

I am trying to read in data from a file using fgetc in a loop like...

while (!feof(fptr))
{
}

but it won't let me read the whole file. If i am correct feof = FFFFFF? The file im trying to read has FFFFFF in it a whole bunch of times and i think that is what is causing the problem.

If i just keep reading regardles of eof then it just keeps reading in F's. I did try to figure out where it finished reading and then use fseek to skip past the FFFFFF and keep reading but screwed up somewhere. It did read some more then stop at an FFFFFF but i got the code to jump to the next bit wrong obviously.

Anyway just wondering if this is my problem and if so has anyone delt with it before.

Cheers for any help.

Comments

  • [blue]feof() returns a non-zero value when end-of-file is reached. The actual contents of the file has nothing to do with this return value, so if your file contains a buch of 0xffff bytes its just a coincidence that your code will not read the file. More than likely the cause is the way the file is opened -- text mode instead of binary mode.[/blue]
    [code]
    // open the file in binary mode
    FILE* fptr = fopen("filename",[red]"rb"[/red]);
    [/code]

  • That could be the problem i think i may have |'d the r and b for some reason. Does that matter?

    Cheers for that

    : [blue]feof() returns a non-zero value when end-of-file is reached. The actual contents of the file has nothing to do with this return value, so if your file contains a buch of 0xffff bytes its just a coincidence that your code will not read the file. More than likely the cause is the way the file is opened -- text mode instead of binary mode.[/blue]
    : [code]
    : // open the file in binary mode
    : FILE* fptr = fopen("filename",[red]"rb"[/red]);
    : [/code]
    :
    :

  • : That could be the problem i think i may have |'d the r and b for some reason. Does that matter?
    [blue]Yes -- they are not the same. It is just "rb".[/blue]
    :
    : Cheers for that
    :
    : : [blue]feof() returns a non-zero value when end-of-file is reached. The actual contents of the file has nothing to do with this return value, so if your file contains a buch of 0xffff bytes its just a coincidence that your code will not read the file. More than likely the cause is the way the file is opened -- text mode instead of binary mode.[/blue]
    : : [code]
    : : // open the file in binary mode
    : : FILE* fptr = fopen("filename",[red]"rb"[/red]);
    : : [/code]
    : :
    : :
    :
    :

  • Computers are soooo full of coincidences :)

    Tried that at lunch and it worked perfectly.

    : : That could be the problem i think i may have |'d the r and b for some reason. Does that matter?
    : [blue]Yes -- they are not the same. It is just "rb".[/blue]
    : :
    : : Cheers for that
    : :
    : : : [blue]feof() returns a non-zero value when end-of-file is reached. The actual contents of the file has nothing to do with this return value, so if your file contains a buch of 0xffff bytes its just a coincidence that your code will not read the file. More than likely the cause is the way the file is opened -- text mode instead of binary mode.[/blue]
    : : : [code]
    : : : // open the file in binary mode
    : : : FILE* fptr = fopen("filename",[red]"rb"[/red]);
    : : : [/code]
    : : :
    : : :
    : :
    : :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories