链表需要帮助,求大佬指导
#include<stdio.h>
#include<stdlib.h>
typedef struct student
{
int xh;
char name[10];
int score[4];
struct student *link;
}STUDENT;
void Output (struct student *head);
struct student *Input(struct student *head);
main()
{
char n;
struct student *head=NULL;
printf("是否继续输入学生信息\n");
scanf(" %c",&n);
while(n=='y'||n=='Y')
{
head=Input(head);
printf("是否继续输入学生信息\n");
scanf(" %c",&n);
}
Output(head);
}
struct student *Input(struct student *head)
{
struct student *pr,*p=NULL,*q=head;//pr找前一个//
int i;
p=(struct student *)malloc(sizeof(struct student));
if(p==NULL)
{
printf("no enough memory");
exit(0);
}
scanf("%d%s",&(p->xh),p->name);
for(i=0;i<4;i )
scanf("%d",&(p->score[i]));
if(head==NULL) head=p;
else
{
while(q!=NULL)
{
pr=q;
q=q->link;
}
q->link=p;
p->link=NULL;
}
return head;
}
void Output (struct student *head)
{
struct student *p=head;
int i;
while(p!=NULL)
{
printf("%d,%s ",p->xh,p->name);
for(i=0;i<4;i )
printf("%d ",p->score[i]);
p=p->link;
}
return;
}