求教链表的基础问题
#include "stdafx.h"#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct line)
#define NULL 0
struct line
{
int a;
int b;
int c;
struct line *next;
};
int n;
struct line *creat(void)
{
struct line *head;
struct line *p1,*p2;
n=0;
p1=p2=(struct line *)malloc(LEN);
scanf("%d",&p1->c);
head=NULL;
while(p1->c!=0)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p1=(struct line *)malloc(LEN);
scanf("%d",&p1->c);
}
p2->next=NULL;
return(head);
}
void main()
{ line *h;
h=creat();
while(h!=NULL)
{printf("%d",h->c);
h=h->next;
}
}
为何不能将链表完全输出而是只输出第一个数??
如何才能将链表完全输出?