我有一个结构作为成员的结构,我想从第一个结构中访问该成员。你没有得到它?我会告诉你。
typedef struct
{
int day;
} Date;
typedef struct
{
struct Date;
} Insert;
Insert insert;
scanf("%d", &insert.day); // I tried this but it doesn't work
scanf("%d", &insert.date.day); // Figured maybe this would do it, but nope
答案 0 :(得分:0)
你需要:
typedef struct
{
Date date;
} Insert;
Insert insert;
然后,
scanf("%d", &insert.date.day);
答案 1 :(得分:0)
正如其他人所说 ,您编写代码的方式不会构建。您应收到错误,如下所示:
typedef struct
{
int day;
} Date;
typedef struct
{
struct Date;//Error here - Undefined size for field, incomplete struct Date defined at cfile.c:8
} Insert;
Insert insert;
int main(void)
{
return 0;
}
您已创建 类型Date
(即typedef struct
... Date
),请使用它代替{ {1}}像这样: (这将构建)
struct Date;