我正在学习C中的嵌套结构,我想要做的是能够为我的结构的成员结构赋值。我无法弄清楚这一点,我不想强迫自己初始化结构的初始化成员结构。为什么我在尝试编译此代码时不断收到错误?如何将值赋给struct的struct成员?
main.c: In function 'main':
main.c:16:23: error: expected expression before '{' token
fooPerson.fullname = {"Foo", 'B', "Baz"};
#define LEN 20
struct names {
char first[LEN];
char middle;
char last[LEN];
};
struct person {
struct names fullname;
};
int main() {
struct person fooPerson;
fooPerson.fullname = {"Foo", 'B', "Baz"};
// NOT this: it works, but not the solution I'm asking for
// struct person fooPerson = {{"Foo", 'B', "Baz"}};
}
只能初始化一次的东西。数组不可分配。 – juanchopanza
对,我编辑了标题以反映您的评论。 – zxgear