为什么我的结构变量不包含此成员?
问题描述:
我写了下面的代码:为什么我的结构变量不包含此成员?
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int month;
int day;
int hour;
int minutes;
}primaries_date;
typedef struct
{
int all_members;
char *country;
primaries_date date;
}usa_primaries;
typedef struct node *ptr;
typedef struct node
{
usa_primaries up;
ptr next;
}Node;
void add(ptr usa_primaries *hptr, int all_members, char *con, int month, int day, int hour, int minutes)
{
ptr p;
ptr q;
ptr t;
t = malloc(sizeof(Node));
if(!t)
{
printf("Cannot build list");
exit(0);
}
t->all_members = members;
t->county = con;
t->date->month = d->month;
t->date->day = d->day;
t->date->hour = d->hour;
while((p1))
{
if(p->date->month >= month || p->date->day >= day || p->date->hour >= hour || p->date->minutes >= minutes)
{
q = p;
p = p->next;
}
}
if(p == *hptr)
{
*hptr = t; /*Resetting head. Assigning to the head t*/
t->next = p;
}
else
{
q->next = t;
t->next = p;
}
}
int main()
{
ptr h;
int month, day, hour, minutes;
int all_memebers; /*Declaration of all_members*/
char *county;
char member;
printf("Please enter the day");
scanf("%d",&day);
printf("Please enter the month");
scanf("%d",&month);
printf("Please enter the hour");
scanf("%d",&hour);
printf("Please enter the minutes");
scanf("%d",&minutes);
printf("Is this an all-member candidate? Y/N");
scanf("%c",&member);
if(member == 'Y')
all_members = 1;
else
all_members = 0;
printf("Please enter the country");
scanf("%s",&county);
add(&h,all_members,country,month,day,hour,minutes);
return 0;
}
我得到这个错误:
usa.c: In function ���add���:
usa.c:42:6: error: ���struct node��� has no member named ���all_members���
t->all_members = members;
^
我真的不明白,为什么这个错误发生,因为all_members在结构usa_primaries宣布,结构节点,其中包含usa_primaries结构。
为什么显示此错误,我该如何解决?
答
Node
没有all_members
。它有一个usa_primaries
和那有all_members
。因此:
t->up.all_members
+0
非常感谢,StoryTeller! – Tree
附注:没有犯法,请重新阅读C书的结构和联合章节。 VTC作为错字。 –
谢谢。我真的意识到那里有很多语法问题,我一直在解决它们,所以现在它编译时没有任何编译错误。 @Sourav Ghosh – Tree
当然,仅供您参考,请了解[___MCVE___](http://stackoverflow.com/help/mcve)。 –