关于链表的,输入若干学生的信息(学号、姓名、成绩),当输入学号为 0 时结束,用单向链表组织这些学生信息后,再按序输出。

输入若干学生的信息(学号、姓名、成绩),当输入学号为 0 时结束,用单向链表组织这些学生信息后,再按序输出。
#include
#include
#include
structstud_node
{
intnum;
char name[20];
int score;
structstud_node next;
};
int main()
{
structstud_node *head,tail,*p;
intnum,score;
char name[20];
int size = sizeof(structstud_node);
head=tail=NULL;
printf(“input num,name and score:\n”);
scanf(“%d”,&num);
while(num != 0)
{
p=malloc(size);
scanf(“%s%d”,name,&score);
p->num=num;
strcpy(p->name,name);
p->score=score;
p->next=NULL;
tail->next=p;
tail=p;
scanf(“%d”,&num);
}
for(p=head;p->next != NULL;p=p->next)
printf(“%d %s %d\n”,p->num,p->name,p->score);
return 0;
}

测试说明
对你编写的代码进行测试:

测试输入:1001,张三,90,1002,李四,85,0
预期输出:
1001 张三 90
1002 李四 85

不行

你直接从头哥复制过来的?

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^

#include
#include
#include
struct stud_node
{
int num;
char name[20];
int score;
struct stud_node *next;
};
int main()
{
struct stud_node *head,*tail,*p;

int num,score;
char name[20];
int size = sizeof(struct stud_node);
head=tail=NULL;
printf("input num,name and score:\n");
scanf("%d",&num);
while(num != 0)
{
scanf("%s%d",name,&score);
p = (struct stud_node *)malloc(size);

p->num=num;
strcpy(p->name,name);
p->score=score;
p->next=NULL;

if(head==NULL)
head=p;
else tail->next=p;
tail=p;
scanf("%d",&num);

}
for(p=head;p;p=p->next)
printf("%d %s %d\n",p->num,p->name,p->score);
return 0;
}