关于c语言结构体嵌套

来源:百度知道 编辑:UC知道 时间:2024/07/02 23:50:25
结构体嵌套:
typedef struct{
int key;
char name[20];
char gender[10];
int sno;
}student;

typedef struct{
student stu[N];
int lengh;
}Table;

以下这句有什么问题:
scanf("%d,%s,%s,%d",&pT->stu[i].key,pT->stu[i].name,pT->stu[i].gender,&pT->stu[i].sno);
error C2227: left of '->stu' must point to class/struct/union
........................

我定义了
Table T
Table *pT=&T

->stu的左边必须是一个Talbe的结构体指针。
scanf("%d,%s,%s,%d",&pT->stu[i].key,pT->stu[i].name,pT->stu[i].gender,&pT->stu[i].sno);
这段代码中的pT就是Table的结构体指针。
可以这样得到:
Table * pT;
pT=(Table *)malloc(sizeof(Table));

是不是编译就过不去啊,试试把第二个结构体定义中的student前加个struct