动态链表问题
程序代码:
#include<stdio.h> #include<malloc.h> #define NULL 0 #define LEN sizeof(struct student) int n=0; struct student { long int num; int score; struct student *next; }; struct student *create(void) { struct student *head; struct student *p1,*p2; p1=p2=(struct student*)malloc(LEN); scanf("%ld,%d",&p1->num,&p1->score); head=NULL; while(p1->num!=0) { n=n+1; if(n==1) head=p1; else p2->next=p1; p2=p1; p1=(struct student*)malloc(LEN); scanf("%ld,%d",&p1->num,&p1->score); } p2->next=NULL; return head; } int main(void) { struct student *head,*stu; head=create();//创建第一个链表 stu=create();//创建第二个链表 print(head);//输出第一个链表 print(stu);//输出第二个链表 return 0; }
第二个链表无输出,why why why???