求助:如下程序是要从链表a中删去与b链表中有相同学号的那些结点, 编译连接都成功了 ,但是运行完printf("\n result:\n");后,就终止了,查找后知道此时的p1已经指向0X00000000,所以没有执行最后得while语句,但为什么
p1指向0X00000000 了呢
#define LA 4
#define LB 5
#define NULL 0
#include<stdio.h>
struct student
{ char num[6];
char name[8];
struct student *next;
}a[LA],b[LB];
main()
{ struct student a[LA]={("101","wang"},{"102","li"},{"105","zhang"},{"106","wei"}};
struct student b[LB]={{"103","zhang"},{"104","ma"},{"105","chen"},{"107","guo"},{"108","lui"}};
int i,j;
struct student *p,*p1,*p2,*Pt,*head1,*head2;
head1=a;
head2=b;
printf("\nlist a:\n");
for(p1=head1,i=1;p1<a+LA;i++)
{ p=p1;
p1->next=a+i;
printf("%8s,%8s\n",p1->num,p1->name);
p1=p1->next;
}
p1->next=NULL;
printf("\n list b:\n");
for(p2=head2,i=1;p2<b+LB;i++)
{ p=p2;
p2->next=b+i;
printf("%8s,%8s\n",p2->num,p2->name);
p2=p2->next;
}
p2->next=NULL;
printf("\n");
p1=head1;
while(p1!=NULL)
{ p2=head2;
while(p2!=NULL&&strcmp(p1->num,p2->num)!=0)
p2=p2->next;
if(strcmp(p1->num,p2->num)==0)
if(p1==head1)
head1=p1->next;
else
p->next=p1->next;
p=p1;
p1=p1->next;
}
p1=head1;
printf("\n result:\n");
while(p1!=NULL)
{ printf("%7s%7s\n",p1->num,p1->name);
p1=p1->next;
}
}