📄 sort.c
字号:
#include <stdio.h>
#include "h.h"
/*按ave排序输出*/
void sort()
{
char c;
if((fp=fopen("student.dat","rb"))==0)
{
printf("cannot open!");
exit(0);
}
for(i=0;fread(&st[i],LEN,1,fp)!=0;i++);
fclose(fp);
n=i;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(st[i].ave<st[j].ave)/*所要条件*/
{
s=st[i];
st[i]=st[j];
st[j]=s;
}
fp=fopen("student.dat","wb");
printf("\nnumber name sex score ave ");
for(i=0;i<n;i++)/*输出语句*/
{
printf("\n%-10s%-10s%10s",st[i].num,st[i].name,st[i].sex);
for(j=0;j<K;j++)
printf("%8d",st[i].score[j]);
printf("%8.2f",st[i].ave);
fwrite(&st[i],LEN,1,fp);
}
fclose(fp);
printf("\n");
printf("\n\tDo you want enter the menu?(y/n)\n\ty--return menu\n\tn--exit:");
getchar();
scanf("%c",&c);
if(c=='y'||c=='Y')
main();
if(c=='n'||c=='N')
exit(0);
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -