Hi,
my problem is that I've got a file in which I've written a string and two integers and I'm trying to read them with this function:
but it seems that my solution to read a string takes one byte more from the file as it should and so my string is "tiles1.bmpd" instead of "tiles1.bmp" and the following ints have the values 6553600 and 0 instead of 100 and 100.
Does anyone have a better solution for reading strings?
thanks for all answers
Let me get this straight, the file has a null terminated string followed immediately by two binary integers? The ints aren't in ASCII?
I think I'm thinking along the same lines as Arthur. My guess is you didn't null terminate, or you had \n in the file before the 0.
Damn, I'm sorry.
I used al_fwrite(file,string,strlen(string)) and not al_fwrite(file,string,strlen(string)+1) to write the string in the file so the '\0'-charakter was missing.
Thanks for the hint
Just so you know, read ints from a file 4 bytes at a time with fread isn't portable. Allegro has functions such as al_fread32le for this purpose.
thanks
So al_fread32le would work on all platforms correct?
If you use that and write32le every time on all platforms then it will work.