al_fseek( file, 4, ALLEGRO_SEEK_SET ); pf(" writing version as 2.\n"); al_fwrite32le( file, (int32_t) 2); al_fseek( file, 4, ALLEGRO_SEEK_SET ); v = al_fread32le( file ); pf(" version is after write is %d.\n",v);
Hi,
in this code, I'm trying to change a number from 1 to 2 in the file.
Since it's an int32_t and the version number is the second number in the file, I call al_fseek(file, 4, ALLEGRO_SEEK_SET) to get to the second int32_t.
After the write, I seek back to the position of the number and read it to v and print it out but it remains 1, not 2 like I'm trying to achieve.
Any ideas why it isn't working ?
Try an al_fflush() after the write?
Cheers Arthur. I put one in but it hasn't changed anything.
What mode are you opening the file as?
I think you want "r+b". Did you check to see if all of your new integers are being appended at the end of the file?
Thanks. It was "r + b" but I thought I needed to change it to "a + b" as I was trying to write to the file, not just to read from it.
I've changed it back and it's working now
.
On to the next problem 
/** EDIT : solved
*/
yeah, when you add a + to the mode, it means to open in read/write mode. r+ means to open rw, with the file pos at the start of the file, and a+ means to open with the file pos at the end. w+ is a bit different, it'll open the file for reading and writing, but it'll truncate the file first.