while循环里的链表要怎么改,加了判定也没有用。

img

这个函数这么写,供参考:

struct student *creat()
{
    struct student *head, *p1, *p2;
    head = NULL;
    printf("请输入学生信息:学号 ,姓名 ,成绩:\n");
    while(1)
    {
        p1 = (struct student*)malloc(LEN);
        if (!p1)  return -1;
        p1->next = NULL;
        scanf_s("%ld %s %f",&p1->num,p1->name,20,&p1->score);
        if (p1->num == 0)  break;
        n++;
        if(n == 1)
           head = p1;
        else
           p2->next = p1;
        p2 = p1;
    }
    free(p1);
    return head;
}