我正在尝试对成绩使用排序功能,它将对“姓名中期1”进行排序,但我不知道如何将姓名和姓氏字符串分配给临时数组。有任何想法吗?
void student_swap(struct student *x){
int z,y,temp;
char temp2[15];
for(z=0; z<10; z++){
for(y=0; y<9; y++){
if(x[y].mid1>x[y+1].mid1){
temp = x[y+1].mid1;
x[y+1].mid1 = x[y].mid1;
x[y].mid1 = temp;
strcpy (temp2,x[y+1].name);
strcpy (x[y+1].name,x[y].name);
strcpy (x[y+1].name,temp2);
strcpy (temp2,x[y+1].surname);
strcpy (x[y+1].surname,x[y].surname);
strcpy (x[y+1].surname,temp2);
} // if
} // for
} // for
} //student_swap
排序int
值工作正常,但strcpy
什么也不做。这是我的输出代码
for (i=9;i>=0;i--){
;
printf ("%s %s %d\n",x[i].name,x[i].surname,x[i].mid1);
}
printf ("\n");
student_swap(x);
for (i=9;i>=0;i--){
;
printf ("%s %s %d\n",x[i].name,x[i].surname,x[i].mid1);
}
这是我的输出
murat hot 73
mehmet umur 72
idil saracoglu 55
ecem bektas 75
sevde pir 70
asli devecioglu 65
can akkurt 45
levent dogan 60
anil erdiz 30
ali durmus 40
murat hot 75
mehmet umur 73
idil saracoglu 72
ecem bektas 70
sevde pir 65
asli devecioglu 60
can akkurt 55
levent dogan 45
anil erdiz 40
ali durmus 30