程序运行结果有问题,帮忙看看。链表
#include "stdio.h"#include "conio.h"
#define NULL 0
#define LEN sizeof(struct student)
struct student
{char num[6];
char name[8];
struct student *next;
};
struct student *creat(void)
{struct student *p1,*p2,*head;
int n=0;
p1=p2=(struct student *)malloc(LEN);
head=NULL;
printf("Input 0 to end.\n");
printf("Input num,name:\n");
scanf("%s,%s",p1->num,p1->name);
while(p1!=NULL)
{if(n==0)head=p1;
else p2->next=p1;
n++;
p1=(struct student *)malloc(LEN);
scanf("%s,%s",p1->num,p1->name);
p2=p1;
}
p2->next=NULL;
return(head);
}
void print(struct student *p)
{while(p!=NULL)
{printf("%4s,%4s\n",p->num,p->name);
p=p->next;
}
}
main()
{struct student *ha,*hb,*p1,*p2,*p;
ha=creat();
hb=creat();
print(ha);
print(hb);
p1=ha;
/*delete*/
while(p1!=NULL)
{p2=hb;
if(p2!=NULL&&strcmp(p2->num,p1->num)!=0)
p2=p2->next;
else
{if(p1==ha)
p1->next=ha;
else
p->next=p1->next;
}
p=p1;
p1=p1->next;
}
print(ha);
getch();
}