链表排序问题
求指导,如何给链表排序,顺便帮我看看这段代码错哪儿了,VC总是提示有空串谢谢啦
#include<stdio.h>
#include<stdlib.h>
#define len sizeof(struct student)
struct student
{
char name[30];
int score1;
int score2;
int score3;
int all;
struct student *next;
};
int n;
struct student*creat()
{
struct student*head;
struct student*p1,*p2; n=0;
p1=p2=(struct student*)malloc(len);
scanf("%s%d%d%d",&p1->name,&p1->score1,&p1->score2,&p1->score3);
head=NULL;
while(p1->name!='')
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(len);
scanf("%s%d%d%d",&p1->name,&p1->score1,&p1->score2,&p1->score3);
}
p2->next=NULL;
return(head);
}
int main()
{
struct student*pt;
pt=creat();
printf("总评1:%d",pt->all=(pt->score1+pt->score2+pt->score3));
printf("总评2:%d",pt->next->all=(pt->next->score1+pt->next->score2+pt->next->score3));
printf("总评3:%d",pt->next->next->all=(pt->next->next->score1+pt->next->next->score2+pt->next->next->score3));
}