我想將uint8_t
數組複製到uint8_t
指針
uint8_t temp_uint8_array[] = {0x15, 0x25, 0x32, 0x00, 0x52, 0xFD};
uint8_t* Buffer = temp_uint8_array;
現在 :
Buffer = {0x15, 0x25, 0x32};
所以我知道我的數據是因為 0x00 被截斷了,有什麼解決辦法嗎?
由於我可以訪問要復制的數據的大小,因此我嘗試使用
memcpy(Buffer, &temp_uint8_array, local_length);
但它不起作用
memcpy 不正確:
memcpy(Buffer, &temp_uint8_array, …
由於 temp_uint8_array 是一個數組,那麼你不應該用 & 前綴:
memcpy(Buffer, temp_uint8_array,…
緩衝區指向 temp_iint8_array,因此 memcpy 除了擦除同一內存位置中的字節外什麼也不做。您的 IDE 可能認為 uint8 數組可以作為字符字符串處理並顯示內容直到 0x00。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句