为什么这个程序运行的时候会创出多余的空链表夹在中间,而且score这个数据也打印不出,找了半天也不知道错在哪(っ╥╯﹏╰╥c)

#include<stdio.h>
#include<stdlib.h>
#define LNE sizeof(struct student)

struct student
{
int num;
int score;
struct student *next;
};
struct student *input()
{
struct student *head,*p1,*p2;
head=NULL;
int n=0;
p2=p1=((struct student *)malloc(LNE));
printf("please input num and score\n");
scanf("%d,%d",&p1->num,&p1->score);
while(p1->num!=0)
{
n++;
if(n==1)
{
head=p1;
}
else
{
p2->next=p1;
}
p2=p1;
p1=((struct student *)malloc(LNE));
printf("please input num and score\n");
scanf("%d,%d",&p1->num,&p1->score);
}
p2->next=NULL;
return head;
}
void output(struct student *head)
{
struct student *p;
p=head;
do
{
printf("%d %d\n",p->num,p->score);
p=p->next;
}while(p->next!=NULL);
}

int main()
{
struct student *c;
printf("please input student data\n");
c=input();
printf("please output student data\n");
output(c);
}

贴出你输入界面,是不是你输入的时候,两个数之间没有加逗号

#include<stdio.h>
#include<stdlib.h>
#define LNE sizeof(struct student)

struct student
{
    int num;
    int score;
    struct student *next;
};
struct student *input()
{
    struct student *head,*p1,*p2;
    head=NULL;
    int n=0;
    p2=p1=((struct student *)malloc(LNE));
    printf("please input num and score\n");
    scanf("%d,%d",&p1->num,&p1->score);
    while(p1->num!=0)
    {
        n++;
        if(n==1)
        {
            head=p1;
        }
        else
        {
            p2->next=p1;
        }
        p2=p1;
        p1=((struct student *)malloc(LNE));
        printf("please input num and score\n");
        scanf("%d,%d",&p1->num,&p1->score);
    }
    p2->next=NULL;
    return head;
}
void output(struct student *head)
{
    struct student *p;
    p=head;
    do
    {
        printf("%d %d\n",p->num,p->score);
        p=p->next;
    }while(p!=NULL);
}

int main()
{
    struct student *c;
    printf("please input student data\n");
    c=input();
    printf("please output student data\n");
    output(c);
}

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632