这个用冒泡排序为什么不按顺序执行呢
# include<stdio.h># include<malloc.h>
struct student
{
int age;
float score;
char name[100];
};
void inputstudent(struct student * a, int len)
{
int i;
for(i=0; i<len; ++i)
{
printf("请输入第%d个人的信息:\n", i+1);
printf("name是:");
scanf("%s", a[i].name);
printf("age = ");
scanf("%d", &a[i].age);
printf("score = ");
scanf("%f", &a[i].score);
}
}
order(struct student * c, int len)
{
int i, j;
struct student t;
for(i=0; i<len-1; ++i)
for(j=0; j<len-1-i; ++j)
{
if(c[j].score < c[j+1].score)
{
t = c[j];
c[j] = c[j+1];
c[j] = t;
}
}
}
void outputstudent(struct student * b, int len)
{
int i;
for(i=0; i<len; ++i)
{
printf("name是:%s\n", b[i].name);
printf("age = %d\n", b[i].age);
printf("score = %f\n", b[i].score);
}
}
int main(void)
{
int len;
printf("请输入学生的个数:\n");
printf("len = ");
scanf("%d", &len);
struct student * st;
st = (struct student *)malloc(sizeof(struct student));
inputstudent(st, len);
order(st, len);
outputstudent(st, len);
return 0;
}
为什么不能正常排序呢?