想用结构体进行成绩排序并且还想调用函数,但不会弄程序一直错误?

img

img


想用结构体进行成绩排序并且还想调用函数,但不会弄程序一直错误,想请教指点,感谢。?

img

img


谢谢指点
但为什么不用函数调用,结构就能直接相互赋值呢?谢谢

错误的原因应该是结构的定义放在使用结构之前(更正一下),修改如下:

#include <stdio.h>

const int n=3,m=10;

struct student{
    
    char name[m];
    int Chinese;
    int English;
    int Math;
};


void arrangement3(struct student s[],int len){
    
    int max=0;
    struct student temp;
    for(int i=0;i<len;i++){
        max=i; 
        for(int j=i+1;j<len;j++){
            
            if(s[j].Chinese>s[max].Chinese){
                
                temp = s[j];
                s[j] = s[max];
                s[max] = temp;
//                strcpy(temp.name,s[i].name);
//                temp.Chinese = s[i].Chinese;
//                temp.English = s[i].English;
//                temp.Math = s[i].Math;
//                
//                strcpy(s[i].name,s[j].name);
//                s[i].Chinese = s[j].Chinese;
//                s[i].English = s[j].English;
//                s[i].Math = s[j].Math;
//                
//                strcpy(s[j].name,temp.name);
//                s[j].Chinese =temp.Chinese;
//                s[j].English = temp.English;
//                s[j].Math = temp.Math;
                
            }
        }
    } 
} 


int main(void){
    struct student s[n] = {
        {"wang",68,98,98},
        {"zhang",98,58,58},
        {"li",78,58,58}
    };
    
    arrangement3(s,3);
    for(int i=0;i<n;i++){
        printf("%s %d %d %d\n",s[i].name,s[i].Chinese,s[i].English,s[i].Math);
    }
    
    return 0;
}

img