gpt4 book ai didi

objective-c - 如何 append 到 Objective c 中的 char 数组

转载 作者:太空宇宙 更新时间:2023-11-04 07:32:53 26 4
gpt4 key购买 nike

我有两个 char 数组 -

char* c1[] = { 0x01, 0x02, 0x03, 0x04, ... 0x016 };
char* c2[] = { 0x01, 0x02, 0x03, 0x04, ... 0x016 };

我想要一个 char (char* result) append 字节 c1c2

最佳答案

您需要分配内存,并将数据从旧数组复制到新数组。

char* result;
result=(char*)malloc( sizeof(c1) + sizeof(c) );
memcpy(result, c, sizeof(c));
memcpy(result+sizeof(c), c1, sizeof(c1));

当你完成你的工作时,使用 free(result);

释放内存

关于objective-c - 如何 append 到 Objective c 中的 char 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11901726/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com