A ver si algun programador caritativo me puede echar una mano, que me estoy volviendo loco con esto.
I have a function that loads from the smc some complex structures, most of the time accesing byte by byte, so it wastes a lot of time.
To avoid this, I'm trying to load in memory the entire file and then select the important data from there. To do so I've used gpbinconv, a little program that creates an array of bytes from any binary file.
My function is:
It reads 2 bytes from file and stores them into A, next stores into B the next 4 bytes. OK, this works well but very slow.
Now I have "array", storing all the data from "file". The code will be as follows:
Now this code reads OK the first time (should read 0x4d4d and so it does) but after that it reads '10' (0x0a) when it should be '9730' (0x00002602) ).
Why it only reads 4bits when it should read 32? And odder, the first case works well... :blink:
I think that the error can lay in the order in which I'm reading the bytes, but I'm not able to find it. Something to do with Big or Little Endian?
Ok, thanks for the time spent reading this post (and trying to understand my english ) I hope someone can help my, 'cos I'm in a hurry.
Locke
I have a function that loads from the smc some complex structures, most of the time accesing byte by byte, so it wastes a lot of time.
To avoid this, I'm trying to load in memory the entire file and then select the important data from there. To do so I've used gpbinconv, a little program that creates an array of bytes from any binary file.
My function is:
Code:
unsigned short A;
unsigned int B;
smc_fread (&A, 2, 1, file);
smc_fread (&B, 4, 1, file);
...
It reads 2 bytes from file and stores them into A, next stores into B the next 4 bytes. OK, this works well but very slow.
Now I have "array", storing all the data from "file". The code will be as follows:
Code:
unsigned short A;
unsigned int B;
int pos = 0;
const unsigned char array[9730] = {77, 77, 2, 38, 0, 0, .........};
A = ((unsigned short *)array)[pos];
pos += 2;
B= ((unsigned int *)array)[pos];
pos += 4;
...
Now this code reads OK the first time (should read 0x4d4d and so it does) but after that it reads '10' (0x0a) when it should be '9730' (0x00002602) ).
Why it only reads 4bits when it should read 32? And odder, the first case works well... :blink:
I think that the error can lay in the order in which I'm reading the bytes, but I'm not able to find it. Something to do with Big or Little Endian?
Ok, thanks for the time spent reading this post (and trying to understand my english ) I hope someone can help my, 'cos I'm in a hurry.
Locke