急 C语言可能循环出现问题 本应该是输入数字 直到输入0就结束,但是最后会一直输出


#include <stdio.h>
#include <stdlib.h>
#include<malloc.h>
#define LEN sizeof(struct int_list)
struct int_list
{
    int value;
    struct int_list *next;
};
typedef struct int_list IntList;
int n;
struct int_list *creat()
{
    struct int_list *head;
    struct int_list *p1,*p2;
    n=0;
    p1=p2=(struct int_list *)malloc(LEN);
    printf("Input:");
    scanf("%d", &p1->value);
    head=NULL;
    while(p1->value!=0)
    {
        n=n+1;
        if(n==1)head=p1;
        else p2->next = p1;
        p2=p1;
        p1=(struct int_list*)malloc(LEN);
        printf("Input:");
        scanf("%d", &p1->value);
    }
    p2->next=NULL;
    return(head);
}

void print(struct int_list *head)
{
    struct int_list *p;
    printf("out");
    p=head;
    if(head!=NULL)
        do
        {
            printf("Output:");
            printf("%d",p->value);
        }while(p!=NULL);
}

int main ()
{
    struct int_list *head;
    head = creat();
    print(head);
    return 0;
}

img