SunLK_25
SunLK_25
2020-06-23 21:38
采纳率: 100%
浏览 143

请问各位大佬这个报错是为什么啊?

图片说明图片说明
#include

typedef struct {
char first[20];
char last[20];
} Name;
typedef struct {
Name name;
int age;
char gender[10];
} Child;

int main(void)
{
Child child = {
{"Meimei", "Han"},
10,
"girl"
};
Child* pc = &child;
printf("%d\n", child.age);
printf("%s\n", pc->name.first);
printf("%s\n", pc->gender);
show(pc);
}
void show(struct Child* pc) {
printf("%s %s is a %d years old %s", pc->name.last, pc->name.first, pc->age, pc->gender);
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • caozhy
    已采纳
    #include <stdio.h>
    
    typedef struct {
        char first[20];
        char last[20];
    } Name;
    typedef struct {
        Name name;
        int age;
        char gender[10];
    } Child;
    
    void show(Child* pc) {
        printf("%s %s is a %d years old %s", pc->name.last, pc->name.first, pc->age, pc->gender);
    }
    
    int main(void)
    {
        Child child = {
            {"Meimei", "Han"},
            10,
            "girl"
        };
        Child* pc = &child;
        printf("%d\n", child.age);
        printf("%s\n", pc->name.first);
        printf("%s\n", pc->gender);
        show(pc);
    }
    

    问题解决的话,请点下采纳

    点赞 评论

相关推荐