为什么程序运行只能输入一次,循环不能进行到底,求大神指教
#include <stdio.h>#include <stdlib.h>
typedef struct STUDENTINF
{
char name[20];
float score;
struct STUDENTINF *next;
}stu;
//创建链表;
struct stu* creat(int n)
{
int i;
stu* head;
stu* note;
stu* end;
head=(stu*)malloc(sizeof(stu));
head=end=NULL;
for(i=1;i<n;i++)
{
note=(stu*)malloc(sizeof(stu));
printf("请输入学生的姓名\n");
scanf("%s",note->name);
printf("请输入学生的成绩\n");
scanf("%d",¬e->score);
end->next=note;
end=note;
}
end->next=NULL;
return head;
}
//遍历链表;
void output(stu *head)
{
stu* note;
note=head;
while(note->next!=NULL)
{
printf("姓名:%s\n",note->name);
printf("成绩:%d\n",note->score);
note=note->next;
}
return ;
}
int main()
{
struct stu* creat(int n);
void output(stu *head);
stu* head;
int n;
printf("请输入创建链表的个数\n");
scanf("%d",&n);
head=creat(n);
output(head);
return 0;
}