链表创建,运行时出现错误?
#include<stdio.h>#include<stdlib.h>
struct student
{
int number;
char name[20];
float score;
struct student*stu;
};
struct student* input(int n)
{
int i;
struct student*next,*end,*put;
put=(struct student*)malloc(sizeof(struct student));
if(put==NULL)
printf("分配内存失败\n");
else
{
printf("======请输入学生的信息======\n");
printf("学号 姓名 总分\n");
scanf("%d%s%f",&put->number,put->name,&put->score);
}
put->stu=NULL;
end=put;
for(i=0;i<n-1;i++)
{
next=(struct student*)malloc(sizeof(struct student));
if(next==NULL)
printf("分配内存失败\n");
else
{
scanf("%d%s%f",&next->number,next->name,&next->score);
next->stu=NULL;
end->stu=next;
end=next;
}
}
return put;
}
int main()
{
int len;
struct student*head;
printf("请输入学生个数:");
scanf("%d",&len);
head=input(len);
return 0;
}
运行时输入第一个学生信息后就出现'运行时错误的提示',好心人帮我看看,谢谢