结构体排序问题求大神
#include <stdio.h>#include <string.h>
/*
*/
struct student
{
int num;
char name[20];
float score;
} stu[3];
void score(student stu[]);
void number();
int main()
{
int d, i;
printf (" 学生成绩管理系统 \n");
printf ("********************************************\n");
printf ("请输入需要统计的学生信息:\n");
do
{
for (i = 0; i < 3; i++)
{
printf ("请输入学生学号:");
scanf ("%d", &stu[i].num);
printf ("请输入学生姓名:");
scanf ("%s", stu[i].name);
printf ("请输入学生成绩:");
scanf ("%f", &stu[i].score);
printf ("\n");
}
printf ("请选择操作:\n");
printf ("1、按成绩排序: ");
printf ("2、按学号排序: \n");
scanf ("%d",&d);
switch(d)
{
case 1: score (stu); break;
case 2: number (); break;
}
}while(stu[i].num!=0);
}
//成绩排序
void score(student stu[])
{
int i,j;
student swap;
for (i = 0; i < 3; i++);
{
for (j = 0; j < 3 - i-1; j++)
{
if (stu[j].score < stu[j+1].score)
{
swap = stu[j];
stu[j]= stu[j+1];
stu[j+1] = swap;
}
}
}
for (i = 0; i < 3; i++)
{
printf("%-10d:%-10s:%10f\n", stu[i].num, stu[i].name, stu[i].score);
}
}
//学号排序
void number()
{
int i,j;
student swap;
for (i = 0; i < 3; i++);
{
for (j = 0; j < 3 - i; j++)
{
if (stu[i].num > stu[i+1].num)
{
swap = stu[i];
stu[i] = stu[i+1];
stu[i+1] = swap;
}
}
}
for (i = 0; i < 3; i++)
{
printf("%-10d:%-10s:%10f\n", stu[i].num, stu[i].name, stu[i].score);
}
}
调用两个子函数实行对结构体里面的东东排序,但是输入了却没有排序,原样输出了,求大神指正