I want to copy an uint8_t
array to a uint8_t
pointer
uint8_t temp_uint8_array[] = {0x15, 0x25, 0x32, 0x00, 0x52, 0xFD};
uint8_t* Buffer = temp_uint8_array;
And now :
Buffer = {0x15, 0x25, 0x32};
So I understand that my data is cut because of 0x00, is there a solution ?
As I have access to the size of tha datas to be copied I tried to use
memcpy(Buffer, &temp_uint8_array, local_length);
But it does not work
CodePudding user response:
uint8_t temp_uint8_array =
is not an array but a syntax error.
So I understand that my data is cut because of 0x00
No it isn't. If you try to interpret the data as a string, then the 0x00 will get treated as a null terminator. But this is not a string.
is there a solution
Don't treat raw data as a string? memcpy
will work perfectly fine.
But it does not work
What doesn't work? What is local_length
and where did you get it from?
CodePudding user response:
Ok so actually it was my variable viewer in my IDE that cuts my variable value so I can only see the value until the 0x00 but in memory the data has been copied.
Maybe it was interpreted as string so it display the value until the null terminator.
To know that I must have check what was going on in my mcu memory with th debugger.
CodePudding user response:
The memcpy isn’t correct :
memcpy(Buffer, &temp_uint8_array, …
As temp_uint8_array is an array then you should not prefix it with & :
memcpy(Buffer, temp_uint8_array,…
Buffer is pointing to temp_iint8_array so the memcpy does nothing but erasing bytes in the same memory location. You IDE might consider that uint8 array may be handled as char string and display contents until 0x00.