这个链表为啥无法输出啊?求解!
#include<stdio.h>#include<stdlib.h>
struct node
{
int num;
struct node*next;
};
void main()
{
int n=0;
struct node*head,*p1,*p2,*p;
p1=p2=(struct node*)malloc(sizeof(struct node));
head=NULL;
printf("输入数据:");
scanf("%d",&p1->num);
while(p1->num!=0)
{
n=n+1;
if(n==0)
head=p1;
else
p2->next=p1;
p1=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p1->num);
}
p2->next=NULL;
p=head;
printf("输出数据:");
while(p!=NULL)
{
printf("%d",p->num);
p=p->next;
}
}