c - 无效的初始化程序 : While assigning value from struct to a struct array

标签 c arrays struct

假设我有两个结构。一个结构体是具有一组元素的简单结构体。

typedef struct __attribute__ ((packed)) {
        float a1;
        float a2;
        uint32_t b1;
        uint32_t b2;
} item;

其他结构只是先前结构item的数组。

typedef struct __attribute__ ((packed)) {
        item item_queue[65000];
} item_arr;

我需要做的是从 item_arr 获取一个元素并将其分配给 item 数组。我正在尝试以这种方式实现它。

item_arr profile_arr[16] = {0};

为 profile_arr 分配值后,我将 item_arr 中的一个元素分配给新的项目数组。

item temp_q[65000] = profile_arr[0].item_queue;

但这给了我错误:无效的初始化程序

我是否以错误的方式进行初始化?任何帮助将不胜感激。

最佳答案

如果您只想将 profile_arr[0].item_queue 复制到 temp_q,则可以使用 memcpy .

void * memcpy ( void * destination, const void * source, size_t num );

memcpy(temp_q, profile_arr[0].item_queue, sizeof(temp_q));

关于c - 无效的初始化程序 : While assigning value from struct to a struct array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53076265/

相关文章:

arrays - 冷聚变 8 : Array of structs to struct of structs

objective-c - 将结构声明为指针,以便可以检查它是否已初始化

比较两个语音

c - 正确sscanf使用麻烦

c - 如何将C中数组中每个单词的首字母大写

javascript - 将 x 和 y 值插入数组变量

C 结构指针访问字段

C、打开gl,绘制直到另一行

c - 局部变量可能尚未初始化

python - 从Python文件中读取多行