#include<stdio.h>
#define LEN sizeof(struct student)
struct student
{int data;
struct student *next;
};
struct student *creat(struct student *head)
{struct student *p1,*newp;
head=(struct student *)malloc(LEN);
p1=(struct student *)malloc(LEN);
scanf("%d",&p1->data);
head=p1;
p1->next=NULL;
newp=(struct student*)malloc(LEN) ;
while(1)
{printf("please input the data");
scanf("%d",&newp->data);
if(newp->data==0)
break;
newp->next=NULL;
p1->next=newp;
p1=newp;
newp=(struct student*)malloc(LEN) ;
}
return head;
}
void Print(struct student *head)
{struct student *p;
p=head;
while(p->next!=NULL)
printf("%d\n",p->data);
p=p->next; }
main()
{struct student *head;
creat(head);
Print(head);
}
虽然通过了编译可是输出结果不对,一直输出很多数字,难道是跳不出while()循环
忘不吝赐教!