您好,我有以下情况
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/