单链表的输出不对,,,
#include<stdio.h>#include<stdlib.h>
#include<string.h>
struct student
{
char name[20];
int age;
float score;
struct student *p;
};
int main()
{
struct student *end,*next,*head,*q;
int iage,i;
float iscore;
char iname[20];
head=(struct student *)malloc(sizeof(struct student));
if(head==NULL)
printf("分配内存失败\n");
else
{
scanf("%s%d%f",iname,&iage,&iscore);
head->score=iscore;
head->age=iage;
strcpy(head->name,iname);
head->p=NULL;
end=head;
for(i=0;i<3;i++)
{
next=(struct student*)malloc(sizeof(struct student));
if(next==NULL)
printf("分配内存不成功\n");
else
{
scanf("%s%d%f",iname,&iage,&iscore);
next->score=iscore;
next->age=iage;
strcpy(next->name,iname);
next->p=NULL;
head->p=next;
end=next;
}
}
}
q=head;
printf("姓名 年龄 成绩\n");
while(q->p!=NULL)
{
printf("%s %d %f\n",q->name,q->age,q->score);
q=q->p;
}
printf("%s %d %f\n",q->name,q->age,q->score);
return 0;
}
输入四个学生信息的时候,怎么只输出了头一个和最后一个的内容,帮我看看,谢谢!