大一刚刚接触c语言,编程出现了问题,不知道错误在哪里
代码如下#include<stdio.h>
int main()
{
struct Student
{
int num;
char name[1000];
char sex;
int age;
int score;
}temp;
int i, j;
struct Student stu[20];
for (i = 0; i<20; i++)
scanf("%d,%s,%c,%d,%d", &stu[i].num, stu[i].name, &stu[i].sex, &stu[i].age, &stu[i].score);
printf("num name sex age score \n");
for (i = 0; i<20; i++)
printf("%-9d%-9s%-9c%-9d%-9d\n", stu[i].num, stu[i].name, stu[i].sex, stu[i].age, stu[i].score);
for (i = 19; i>0; i--)
{
for (j = 19; j>19 - i; j--)
if (stu[j].score>stu[j - 1].score) temp = stu[j], stu[j] = stu[j - 1], stu[j - 1] = temp;
}
printf("num name sex age score \n");
for (i = 0; i<20; i++)
printf("%-9d%-9s%-9c%-9d%-9d\n", stu[i].num, stu[i].name, stu[i].sex, stu[i].age, stu[i].score);
return 0;
}
然后结果变成这样了,不知道哪里变量定义错误或者输入输出出现问题。希望有大神帮忙看看!