请问这个代码应该怎么改,求大神指导啊!!!
请问这个代码该怎么改才能当我不想排序的时候可以直接退出,我的代码是按了0之后还会排序一次,再按一次才能退出,我想要让它直接退出.#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXID 6
#define MAXNAME 8
#define MAXN 100000
struct Student{
char id[MAXID + 1];
char name[MAXNAME + 1];
int grade;
}Record[MAXN];
int CompareId(const void *a, const void *b)
{
return strcmp(((const struct Student *)a)->id, ((const struct Student *)b)->id);
}
int CompareName(const void *a, const void *b)
{
int k = strcmp(((const struct Student *)a)->name,((const struct Student *)b)->name);
if (!k)
strcmp(((const struct Student *)a)->id, ((const struct Student *)b)->id);
return k;
}
int CompareGrade(const void *a, const void *b)
{
int k = (((const struct Student *)a)->grade>((const struct Student *)b)->grade)?1:0;
if (!k){
k = (((const struct Student *)a)->grade<((const struct Student *)b)->grade) ? -1 : 0;
if (!k)
strcmp(((const struct Student *)a)->id, ((const struct Student *)b)->id);
}
return k;
}
int main()
{
int N, C, i;
printf("请输入记录的条数:\n");
scanf("%d", &N);
printf("请输入学生记录(格式为:学号 姓名 成绩):\n");
for (i = 0; i < N; i++)
{
scanf("%s %s %d",&Record[i].id,&Record[i].name,&Record[i].grade);
}
while(C!=0);
{
printf("请输入指定排序的列号:\n");
scanf("%d",&C);
switch (C)
{
case 1:qsort(Record, N, sizeof(struct Student), CompareId);
break;
case 2:qsort(Record, N, sizeof(struct Student), CompareName);
break;
case 3:qsort(Record, N, sizeof(struct Student), CompareGrade);
break;
}
printf("排序后的结果为:\n");
for (i = 0; i < N; i++)
printf("%s %s %d\n", Record[i].id, Record[i].name, Record[i].grade);
}
return 0;
}