c - 使用 ansi c 将对象存储在数组中?

标签 c visual-c++ c89

我制作了一个类似的结构

struct abc {
    //any function or variable
} obje[20];

现在我希望将 abc 的每个对象存储在数组中。表示arr[0]仅包含obj[0];可以吗这是可能的。如果可能的话,有人会在这件事上帮助我。

最佳答案

如果要从数组中复制对象obje进入数组arr ,您可以使用memcpy()来自<string.h> :

#include <string.h>

struct abc arr[20];

memcpy(&arr, &obje, sizeof arr);

/* Now arr[0] has a copy of obje[0], arr[1] has a copy of obje[1], ... */

关于c - 使用 ansi c 将对象存储在数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3666139/

相关文章:

c - c中的两个函数使用相同的指针

visual-c++ - fatal error LNK1112 : module machine type 'X86' conflicts with target machine type 'AMD64'

c - MS VS 2008 和 C99

c - 寄存器和临时寄存器有什么区别?

c - C语言:\r or\n?换行符是什么

c - uint8_t 与无符号字符

c++ - ifstream::read 在 ASCII 26 处失败

c++ - 无法取消引用 map const 迭代器的 mapped_type

c - 异常行为 : typedef and object of same name

c - 我应该使用哪种类型的指针? ptrdiff_t 还是 void*?