如何在c

时间:2018-06-25 17:47:53

标签: c

void *val1 = (uint8_t []){0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};

size_t val1_len = 20;

void* val2 = (uint8_t[]){0x1, 0xf, 0xc, 0x3};

size_t val2_len = 4;

void *val3 = (uint8_t[]){0x1, 0x1, 0xc, 0x4, 0x5, 0x7, 0xa, 0x4};

size_t val3_len = 8;

我将这些值称为val1val2val3。现在,如何将它们连接起来,使我得到

val1后跟val2,后跟val3作为输出

1 个答案:

答案 0 :(得分:1)

void *val4 = malloc(val1_len + val2_len + val3_len);
memcpy(val4, val1, val1_len);
memcpy(val4+val1_len, val2, val2_len);
memcpy(val4+val1_len+val2_len, val3, val3_len);