#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student
{
int id;
char name[20];
int score1,score2,score3;
struct student *next;
};
typedef struct student SNODE;
SNODE *creat(SNODE *head)
{
SNODE *r,*s;
int id;
char name[20];
int score1,score2,score3;
head=(SNODE *)malloc(sizeof(SNODE));
r=head;
printf("输入学号:\n");
scanf("%d",&id);
while(id!=0)
{
printf("输入姓名:\n");
scanf("%s",name);
printf("输入三门课程的成绩:\n");
scanf("%d%d%d",&score1,&score2,&score3);
s=(SNODE *)malloc(sizeof(SNODE));
s->id=id;strcpy(s->name,name);s->score1=score1;
s->score2=score2;s->score3=score3;
r->next=s;
r=s;
printf("输入学号:\n");
scanf("%d",&id);
}
r->next='\0';
return head;
}
void print(SNODE *head)
{
SNODE *p;
p=head->next;
if(p=='\0') printf("LinkList is NULL!\n");
else
{
printf("StudentInformation:\n");
do{
printf("%d %s %d %d %d\n",p->id,p->name,p->score1,p->score2,p->score3);
p=p->next;
}while(p!='\0');
}
printf("\n");
}
SNODE *insert(SNODE *head,int x,int y,char str[],int z1,int z2,int z3)
{
SNODE *p1,*p2,*s;
s=(SNODE *)malloc(sizeof(SNODE));
s->id=y;strcpy(s->name,str);s->score1=z1;
s->score2=z2;s->score3=z3;
p1=head;
p2=head->next;
while((p2!='\0')&&(p2->id!=x))
{
p1=p2;
p2=p2->next;
}
s->next=p2;
p1->next=s;
return head;
}
int main()
{
SNODE *head;
int new_id,new_score1,new_score2,new_score3,x;
char str[20];
head=NULL;
head=creat(head);
print(head);
printf("输入插入位置:\n");
scanf("%d",&x);
printf("输入插入的数据:\n");
scanf("%d%s%d%d%d",&new_id,str,&new_score1,&new_score2,&new_score3);
head=insert(head,x,new_id,str,new_score1,new_score2,new_score3);
print(head);
return 0;
}
请修改