gpt4 book ai didi

C - 将两个结构附加到单个缓冲区

转载 作者:太空宇宙 更新时间:2023-11-04 02:02:14 25 4
gpt4 key购买 nike

我需要这样做,以便两个结构的内容将位于两个结构大小的单个缓冲区内。我需要使用 memcpy 来执行此操作。

这是我当前的代码:

struct Header header;
struct Data_Format DF;

char *buffer[28];

header.Start = 0x7E;
header.Options = 0x00;

DF.Address = 0x007CB;
DF.Result = 0x105BA;

memcpy(buffer,&header,sizeof(header));

我如何才能使 DF 结构在 header 完成的地方继续?

最佳答案

试试这个:

char buffer[sizeof(header)+sizeof(DF)];
...
memcpy(buffer,&header,sizeof(header));
memcpy(buffer+sizeof(header),&DF,sizeof(DF));

关于C - 将两个结构附加到单个缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25758920/

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