输入学生信息,输入学号0时结束,建立单项链表,在输入一个成绩,将大于它的输出,我的代码哪儿错了

我用的VC6.0代码如下
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct stud_node{
int num;
char name[20];
int score;
struct stud_node*next;

};
int main(void)
{
struct stud_node *head,*p,*tail;
int num,score,m;
char name[20];
struct stud_node *ptr;
int size=sizeof(struct stud_node);
head=tail=NULL;
printf("Input num,nameandscore:\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;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
scanf("%d",&num);
}
printf("please enter m:");
scanf("%d",&m);
if(head==NULL){
printf("\n no records");
return 0;
}
for(ptr=head;ptr;ptr=ptr->next)
{
if(ptr->score>=m)
printf("%8d%20s%6d\n",ptr->num,ptr->name,ptr->score);
}
return 0;

}
最终结果有点问题

if(head==NULL)
head=p;
else
tail->next=p;

改为

if(head==NULL)
{
head=p;
tail = p;
}
else
tail->next=p;
温馨提示:答案为网友推荐,仅供参考