- Online Community Forums » Allegro Development » al_fread problems on Windows

This thread is locked; no one can reply to it. rss feed Print
al_fread problems on Windows
Michael Moffitt
Member #15,246
July 2013

Using 5.0.10 on Windows, I'm unable to correctly use al_fread.

I have a struct, 102 bytes in size, which I save directly to a file to store the game configuration. Under all operating systems the write works correctly. Using a hex editor I can verify the data is stored correctly, and is the right size.

When loading it, all 102 bytes are fine except on Windows, where invariably after 20 bytes al_feof returns true. I've tried loading this in every way I can think of, including abuse of al_fgetc, manually looping with al_fread16le, and loading with al_fread pointing to the struct address I want to fill. Always it loads twenty bytes, and does not set an error flag.

Screenshots of the problem are attached to this post. In the terminal I am rendering the read struct contents, and when it fails my sanity check it writes a new copy with the correct data visible below it. The hex editor is the data shown correctly on disk, and the relevant code is included as well.

Does anyone know what's going on here?

Todd Cope
Member #998
November 2000

If you are reading/writing binary data, try al_fopen("file", "rb") and al_fopen("file", "wb"). Not sure if it is the source of your problem, but I had similar issues in the past which were solved by doing this.

Michael Moffitt
Member #15,246
July 2013

There it is, I did forget to specify binary reading/writing. Thanks for the tip. It works great now.

Go to: