#include<stdio.h>
#include<stdlib.h>
struct stu
{
char name[5];
int mark;
};
int cmp(const void *q, const void *p)
{
return ((struct stu*)q)->mark - ((struct stu*)p)->mark;
}
int main()
{
struct stu file[5];
for (int i=0;i<5;i++)
{
scanf_s("%s %d", file[i].name, &file[i].mark);//在devc++
//中按回车仍可继续输入,而在vs2019中按回车就直接结束程序了。
}
qsort(file, 5, sizeof(struct stu), cmp);
for (int i = 0;i < 5;i++)
{
printf("%s %d", file[i].name,file[i].mark);
}
}
希望输入的格式是:
name1‘空格’mark1‘\n’
name2‘空格’mark2‘\n’
name3‘空格’mark3‘\n’
name4‘空格’mark4‘\n’
name5‘空格’mark5‘\n’