这是书上的例子,代码如下
#define MAX 30
typedef struct datatype{
int year;
char month[12];
int date;
}DATE;
typedef struct personnel{
char name[20];
char sex[8];
DATE birthday;
char speciality[20];
char class1[10];
}PERSONNEL; /*typedef struct personnel PERSONNEL;错误的例子*/
PERSONNEL student[MAX];
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i,total;
printf("input the total number of students:");
scanf("%d",&total);
for(i=0;i<total;i++)
{
printf("input the %d student's name,sex:",i);
scanf("%s,%s",student[i].name,student[i].sex);
printf("input the year month,date of %d student's birthday:",i);
scanf("%d,%s,%d",student[i].birthday.year,student[i].birthday.month,student[i].birthday.date);
printf("input the speciality,class of %d student:",i);
scanf("%s,%s",student[i].speciality,student[i].class1);
}
for(i=0;i<total;i++)
{
printf("|%2d|%-6s",i,student[i].name);
printf("|%2s",i,student[i].sex);
printf("|%4d",i,student[i].birthday.year);
printf("|%2s",i,student[i].birthday.month);
printf("|%2d",i,student[i].birthday.date);
printf("|%12s",i,student[i].speciality);
printf("|%8s|\n",i,student[i].class1);
}
system("pause");
return 0;
}
运行时在红字处出现错误,程序直接跳出。到底是那里错了?