Folks,
I have a one_byte_array[32], and I have 2_bytes_struct{element1, element2, element3, element4}
I am trying to copy the first 10 bytes of one_byte_array into 2_bytes_struct.
I used this, but its not working properly: memcpy(&(2_bytes_struct),one_byte_array,11);
I believe is a formatting issue that I'm having in the data after I pass it. I get a value of zero for each element in 2_bytes_struct after the copying is done. And when I print one_byte_array I can see its data.
one_bye_array is has the first 11 elements (The ones I want) stored in the following order:
{value1, value2 lsb, value2 msb, value3 lsb, value3 msb, value4 lsb, value4 msb, value5 lsb, value5 msb, value6, value7}
For instance, value2 lsb and value2 msb shall be stored in element1 of the struct (since element1is two bytes), and so forth.
How can I fix and store the data correctly? Any bit shifting that needs to be done here?
Actual code:
typedef struct
{
UINT8 element1;
INT16 element2;
INT16 element3;
INT16 element4;
INT16 element5;
INT16 element6;
} 2_bytes_struct;
UINT8 one_byte_array[32];
memcpy(&2_bytes_struct, one_byte_array, 11);