我想创建一个学生信息成绩册,程序如下,能输入,但显示不出来,怎么回事啊?求助
#include
#include
#define NULL 0
#define LEN sizeof(struc
我想创建一个学生信息成绩册,程序如下,能输入,但显示不出来,怎么回事啊?求助
#include
#include
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
long stu_num;
char stu_name;
float stu_score;
struct student *next;
};
int n;
void main()
{
struct student *creat(void);
struct student *ty;
printf("\nPlease input the student information:");
printf("\nas the order of student number:\n");
ty=creat();
printf("\nNow,These records are:\n");
if(ty!=NULL)
do
{printf("%ld %s %5.1f\n",ty->stu_num,ty->stu_name,ty->stu_score);
ty=ty->next;
}while(ty!=NULL);
}
struct student *creat(void)
{
struct student *head;
struct student *t1,*t2;
n=0;
t1=t2=(struct student*)malloc(LEN);
scanf("%ld,%s,%f",&t1->stu_num,&t1->stu_name,&t1->stu_score);
head=NULL;
while(t1->stu_num!=0)
{
n=n+1;
if(n==1)head=t1;
else t2->next=t1;
t2=t1;
t1=(struct student*)malloc(LEN);
scanf("%ld,%s,%f",&t1->stu_num,&t1->stu_name,&t1->stu_score);
}
t2->next=NULL;
return(head);
}
展开
全部