为什么没有由小到大排序?

#include <stdio.h>
#define N 4
struct student
{
    char name[30];
    double score;
};
void input(struct student *p, int len){
    for(int i=0;i<len;i++){
        printf("please input number %d student`s name and score:\n",i+1);
        scanf("%s %lf",p[i].name,&p[i].score );        
    }
}
void sort(struct student *p,int len){
    for(int i=0;i<len-1;i++){
        for(int j=0;j<len-i-1;i++){
            if(p[j].score >p[j+1].score){
            struct student  b=p[j];
            p[j]=p[j+1];
            p[j+1]=b;
        }
        }
    }
}
void output(struct student *p,int len){
    for(int i=0;i<len;i++)
    printf("NO.%dstudent name:%s,score :%lf\n",i+1,p[i].name ,p[i].score );
}
int main(void){
    struct student a[N];
    input(a,N);
    sort(a,N);
    output(a,N);
    return 0;
}

因为排序函数sort()第二个for循环里的i++错了,因为这个for循环的循环变量是j,不是i, 把它改为j++就可以了,修改如下:

#include <stdio.h>
#define N 4
struct student
{
    char name[30];
    double score;
};
void input(struct student *p, int len){
    for(int i=0;i<len;i++){
        printf("please input number %d student`s name and score:\n",i+1);
        scanf("%s %lf",p[i].name,&p[i].score );        
    }
}
void sort(struct student *p,int len){
    for(int i=0;i<len-1;i++){
        for(int j=0;j<len-i-1;j++){ //把这里的i++改为j++,因为这里的循环变量是j 
            if(p[j].score >p[j+1].score){
            struct student  b=p[j];
            p[j]=p[j+1];
            p[j+1]=b;
        }
        }
    }
}
void output(struct student *p,int len){
    for(int i=0;i<len;i++)
    printf("NO.%dstudent name:%s,score :%lf\n",i+1,p[i].name ,p[i].score );
}
int main(void){
    struct student a[N];
    input(a,N);
    sort(a,N);
    output(a,N);
    return 0;
}

img