关于链表输出
#include "stdio.h"#include "conio.h"
#define NULL 0
#define LEN sizeof(struct student)
struct student
{long num;
int score;
struct student *next;
};
struct student listA,listB;
int n,sum=0;
struct student *creat(void)
{struct student *p1,*p2,*head;
int n=0;
printf("Input 0 to end.\n");
printf("Input number,score:\n");
p1=p2=(struct student *)malloc(LEN);
scanf("%d,%d",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{if(n==0)head=p1;
else p2->next=p1;
p2=p1;
n++;
p1=(struct student *)malloc(LEN);
scanf("%ld,%d",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}
struct student *insert(struct student *ah,struct student *bh)
{
}
void print(struct student *head)
{struct student *p;
printf("\nThere are %d records:\n",sum);
p=head;
if(p!=NULL)
do
{printf("%ld%5d\n",p->num,p->score);
p=p->next;
}
while(p!=NULL);
}
main()
{struct student *ahead,*bhead,*abh;
printf("\nInput list a:\n");
ahead=creat();
sum=sum+n;
printf("\nInput list b:\n");
bhead=creat();
sum=sum+n;
abh=insert(ahead,bhead);
print(ahead);
getch();
}
为什么sum输出还为0;还有第一条记录输出老是出错,帮忙看看,谢谢。