#define NULL 0
#define len sizeof(struct zhi)
#include "stdio.h"
struct zhi
{int a;
 struct zhi *next;
 };
struct zhi *creat()
{struct zhi *p1;
 struct zhi *p2;
 struct zhi *head;
 int n=0;
 p1=p2=(struct zhi *)malloc(len);
 scanf("%d ",&p1->a);
 head=NULL;
 while(p1->a!=NULL)
 { n=n+1;
  if(n==1)
   {head=p1;
    p2=p1;
   }
  else
   {p1=(struct zhi *)malloc(len);
   scanf("%d ",&p1->a);
   p2->next=p1;
   p2=p1;
   }
 }
  p2->next=NULL;
  return(head);
}
 main()
 {struct zhi *p;
  p=creat();
  while(p->next!=NULL)
  { printf("%d ",p->a);
    p=p->next; }
 }
这是个链表的输入,输出程序。
我想得到的是输入:12 54 65 0 输出:12 54 65 
但是实际上输入是: 12 54 65 0 0 才能得到:12 54 65  
谁能帮解决一下。我已经想了一天了。



 
											





 
	    

 
	
 
											




