【发布时间】:2020-04-15 07:35:33
【问题描述】:
我想知道如何按数组对名称进行排序。 我对排序和打印有疑问。我不知道,因为我是 C 编程的初学者。请给我建议(对不起我的英语)谢谢。
code that i have
#include<stdio.h>
#include<string.h>
#include <ctype.h>
int main(){
int i = 0;
char choose[10];
struct Student{
char name[61];
char surname[61];
char sex[10];
char age[3];
char id[12];
float gpa;
}student[20];
for(i=0;i<20;i++){
scanf("%s %s %s %s %s %f",student[i].name, student[i].surname, student[i].sex,student[i].age,student[i].id,student[i].gpa);
}
for(int i =0;i<20;i++){
//sort
}
}
【问题讨论】:
-
研究使用
qsort()。它可以使用用户定义的比较函数对您的数据进行排序......您不需要来回移动元素,这一切都在内部发生。