I want to read data from a .bin file. Actually If I preview the data of my bin file I see something like this:
0000000 3030 3030 3030 3730 300a 3030 3030 3030
0000010 0a35 3330 3030 3030 3030 300a 3031 3030
So I just want to read first the first 2 32-bit signed int.
My code is this:
int data,data2;
fread(&data,4,1, ptr_myfile);
printf("First Data read in hex is: %x\n",data);
/*read the second 32 bit integer*/
fread(&data2,sizeof(int),1, ptr_myfile);
printf("Second data read in hex is: %x\n",data2);
My output is this:
First Data read in hex is: 30303030
Second data read in hex is: 37303030
- So my first question is why they are read in this order? and the second one is not 30303730? and which one is the correct under the assumption that I have to read the first two signed 32 bit integers?
And more important
- The second number declares the rest 32 bit signed ints that should exist in the bin file. There are some notes that describe this bin file and I know that the second number should be equal to 4, or a little bit bigger but at no case 37303030 which is extremely large number.
I think there is something wrong with my conversion or the way I read the bin file.
The bin file is supposed to contain:
EDIT:
The bin file is ASCII text with UNIX-style line-endings. It
consist of a series of 32-bit signed integers in hexadecimal only
Any help on what am I missing here?