结构体之间的嵌套 为什么运行不了?
程序代码:
#include <stdio.h> #include <stdlib.h> typedef struct{ char name[10]; char sex; unsigned int age; }Person; typedef struct{ int math; int english; int chinese; int average; }Grade; typedef struct{ Person person; long number; Grade grade; }Student; void personInput(Person *pPerson); void personOutput(Person *pPerson); void gradeInput(Grade *pGrade); void gradeOutput(Grade *pGrade); void studentInput(Student *pstudent); void studentOutput(Student *pstudent); int main() { int i; Student stu[]={{},{}}; printf("请输入学生信息:"); studentInput(&stu[i]);} if(Student stu[0]->Grade->average<Student stu[1]->Grade->average) printf("%s 比 %s 平均成绩低",stu[0],stu[1]); else printf("%s 比 %s 平均成绩低",stu[1],stu[0]); for(i=0;i<2;i++) studentOutput(&stu[i]); printf("So Easy!"); return 0; } void personInput(Person *pPerson){ printf("请输入姓名:"); scanf("%s",pPerson->name); getchar(); printf("请输入性别:"); scanf("%c",&(pPerson->sex)); printf("请输入年龄:"); scanf("%u",&(pPerson->age));} void personOutput(Person *pPerson){ printf("person:%s的个人信息为:\n",pPerson->name); printf("\t Name: %s\n",pPerson->name); printf("\t Sex : %c\n",pPerson->sex); printf("\t Age : %d\n",pPerson->age); } void gradeInput(Grade *pGrade){ printf("请输入数学成绩:"); scanf("%d",&pGrade->math); printf("请输入英语成绩:"); scanf("%d",&pGrade->english); printf("请输入语文成绩:"); scanf("%d",&pGrade->chinese); printf("请输入平均分成绩:"); scanf("%d",&pGrade->average); } void gradeOutput(Grade *pGrade){ printf("\t 数学:%d\n",pGrade->math); printf("\t 英语:%d\n",pGrade->english); printf("\t 语文:%d\n",pGrade->chinese); printf("\t 平均分:%d\n",pGrade->average); } void studentInput(Student *pstudent){ personInput(&pstudent->person); printf("请输入学号:\n"); scanf("%ld",&pstudent->number); gradeInput(&pstudent->grade); } void studentOutput(Student *pstudent){ personOutput(&pstudent->person); gradeOutput(&pstudent->grade); printf("学号:%ld",pstudent->number); }
麻烦大神看一下
[此贴子已经被作者于2016-12-13 14:12编辑过]