Help on fwrite() and fread() an int
Can somebody help me. I am having problems storing a signed long int ('s64') to a file. For some reason when blob.pos is > 127 when I read it from the file it will return junk value.
I think it has something to do with the endiannes. I checked the bits of blob.pos and the junk value. The rightmost bits of the junk value matched blob.pos but the rest are 1.
sample:
junk val - 1111 1111 1111 1111 1111 1111 1101 0110 : -43
blob.pos - 0000 0000 0000 0000 0000 0000 1101 0110 : 214
Here's my fwrite code.
Code:
fwrite(&(blob.pos), sizeof(s64), 1, fp);
Thank you for your help.