C语言,建立一个单向链表,再输入一个成绩值,将成绩大于等于该值的学生信息输出。

//1.输入若干个学生信息(包括学号、姓名和成绩),
//输入学号为0时输入结束,建立一个单向链表,再输入一个成绩值,将成绩大于等于该值的学生信息输出。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student{
int num;
char name[20];
int score[10];
struct student *next;
};

int main()
{
struct student *head,*tail,*p;
int num,score[10],i=1;
char name[20];
int size=sizeof(struct student);

head = NULL;
printf("1输入学号姓名成绩\n");
scanf("%d%s%d",&num,name,&score[i]);

while(num!=0)
{
p=(struct student*)malloc(size);
p->num = num;
strcpy(p->name,name);
p->next =NULL;

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

printf("输入学号姓名成绩\n");
scanf("%d%s%d",&num,name,&score[i]);
if(score[i]>score[i-1])
printf("%d%s%d",num,name,score[i]);
else
printf("%d%s%d",num,name,score[i-1]);

i=i+1;
}

return 0;
}

首先,scanf("%d%s%d",&num,name,&score[i]); 每个百分号用空格或者逗号隔开,系统不会给你区别你现在输入的是字符串还是数字,你的%s%d,假设你输入是的qwe123,只会认为你qwe123是一个字符串,而不是qwe 是字符串,123是分数,这能解决你运行不过去的问题,至于结果,你的算法有问题,自己再改改
温馨提示:答案为网友推荐,仅供参考