在结构体中还有结构体如何用指针访问?
程序代码:
#include <stdio.h> #include <stdlib.h> struct date { int year; int month; int day; }; struct student { char name[20]; char sex[4]; struct date birthday; }; void Insert(struct student *,int ); void Display(struct student *,int); int main(void) { struct student stu[20]; Insert(stu,2); Display(stu,2); system("pause"); return 0; } void Insert(struct student *stu,int n) { struct student *p; for(p=stu; p<stu+n; p++) { scanf("%s",p->name); scanf("%s",p->sex); scanf("%d",p->birthday->year); scanf("%d",p->birthday->month); scanf("%d",p->birthday->day); } } void Display(struct student *stu,int n) { struct student *p; for(p=stu; p<stu+n; p++) { printf("%s ",p->name); printf("%s ",p->sex); printf("%d-",p->birthday->year); printf("%d-",p->birthday->month); printf("%d",p->birthday->day); printf("\n"); } }
我这样访问是错误的有大神能指导下不