这串代码哪里错了void sort_grades(int grades[], char id[][max_id_length], char names[][max_name_length], int n) { int temp; char temp_name[max_num][max_name_length]; char temp_id[max_num][max_id_length]; int i,j; for(i = 0; i<n-1 ; i++) { for(j =0; j<n-1-i ; j++); { if(grades[i] < grades[i + 1]) { temp = grades[i]; grades[i] = grades[i + 1]; grades[i + 1] = temp; strcpy(temp_name,names[i]); strcpy(names[i],names[i+1]); strcpy(names[i+1],temp_name); strcpy(temp_id,id[i]); strcpy(id[i],id[i+1]); strcpy(id[i+1],temp_id); } } } }
时间: 2023-11-17 17:04:50 浏览: 40
该代码在第二个 for 循环中有一个多余的分号,导致循环体为空,因此无法进行排序。正确代码如下:
```
void sort_grades(int grades[], char id[][max_id_length], char names[][max_name_length], int n) {
int temp;
char temp_name[max_num][max_name_length];
char temp_id[max_num][max_id_length];
int i, j;
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - 1 - i; j++) {
if (grades[j] < grades[j + 1]) {
temp = grades[j];
grades[j] = grades[j + 1];
grades[j + 1] = temp;
strcpy(temp_name, names[j]);
strcpy(names[j], names[j + 1]);
strcpy(names[j + 1], temp_name);
strcpy(temp_id, id[j]);
strcpy(id[j], id[j + 1]);
strcpy(id[j + 1], temp_id);
}
}
}
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)