c - C 中的结构复制,其中结构是元素

标签 c struct

您好,我有以下情况

typedef struct
{
    int a;
    Name team[5];
    Sport sport[5];
} School;

where Name and Sport are also structs,

typedef struct
{
    char arry[20];
}Name;

typedef struct
{
        char arry[20];
        int tag;
}Sport;

然后

School first_school, second_school;

我单独填充它们,然后在某个时候我这样做

first_school = second_school

但是我单步执行代码,这行似乎不起作用。我该如何复制?

最佳答案

But I step through code this line doesn't seem to work. How should I copy ?

像这样复制结构是完全正确的

first_school = second_school; // valid

如果它没有按预期工作,那么错误就在其他地方。例如,您需要对字符串成员执行strcpy()

关于c - C 中的结构复制,其中结构是元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41138661/

相关文章:

python - OpenCV颜色识别

c - GDB 不会在没有 step-mode=on 的情况下单步执行函数

c - 使用 C 中的结构将数据存储到动态数组中

c - 在 C 中按下向上箭头键时,如何立即采取行动?

c - 在现有的 C 项目上使用 Go

c - 如何在 C 中使用 strtok 删除 char 数组中的最后一个字符串?

c - C 中的结构 x 与 x_t

c - 具有灵活数组成员的结构数组如何表现?

c# - 就地使用 Vector2f 结构数组作为 float 数组

arrays - 为什么我不能在 Swift 中使用数组的 append()?