链表出错,未知原因,有兴趣的进来看看!!!!
struct pcb{ char a[10]; /*编号*/
char kehu[40]; /*客户*/
char gongyi[30]; /*工艺*/
char kebian[50]; /*客编*/
char beizhu[200]; /*备注*/
struct pcb *next;
}*head,*no1,*no2;
for(z=0;;z++)
{
if(z==1)head=no2;
no1=(struct pcb *)malloc(sizeof(struct pcb));
if(no1==NULL)exit(1);
printf("\nNO.%d----------------\nbianhao: ",z+1);
scanf("%10s",&(no1->a));
if(!strcmp(no1->a,"bye")||!strcmp(no1->a,"exit")||!strcmp(no1->a,"qiut"))
{
free(no1);
no2=no2->next=no1=NULL;
break;
}
printf("kehu: ");
scanf("%40s",&(no1->kehu));
printf("gongyi: ");
scanf("%30s",&(no1->gongyi));
printf("kebian: ");
scanf("%50s",&(no1->kebian));
printf("beizhu: ");
scanf("%200s",&(no1->beizhu));
if(z!=0)
no2->next=no1;
no2=no1;
}
no2=head;
while(no2)
{
printf(" %s\n%s\n%s\n%s\n%s\n",no2->a,no2->kehu,no2->gongyi,no2->kebian,no2->beizhu);
no2->next=no2;
}
这是一个建立链表并按用户的意图分别对各节点赋值.链表表头为head!!!但遗憾的很,不知道是什么原因,输出链表时,只显示head 所指的节点数据,然后就结束了!!!!大家分析一下这是什么原因而导致的!!!!!
[[italic] 本帖最后由 dsjdcy 于 2007-12-14 07:17 编辑 [/italic]]