#include <stdio.h>
void sort(struct student st[]);
struct student
{ int number;
char name;
double score;
};
int main()
{ struct student st[10];
int i;
FILE *fp,*fpout;
fp=fopen("stu1.txt","r+");
if(fp==NULL)
{printf("文件打开失败\n");
return 0;}
for(i=0;i<10;i++)
fscanf(fp,"%d%s%lf",&st[i].number,&st[i].name,&st[i].score);
sort(st);
fpout=fopen("044.txt","w");
if(fpout==NULL)
{printf("打开文件044.txt失败\n");
return 0;}
for(i=0;i<10;i++)
fprintf(fpout,"%d %s %lf",st[i].number,st[i].name,st[i].score);
fclose(fp);
fclose(fpout);
return 0;
}
void sort(struct student st[])
{ struct student temp;
int i,j;
for(i=0;i<10;i++)
{for(j=0;j<10-i-1;j++)
{if(st[j].score>st[j+1].score)
{temp=st[j];
st[j]=st[j+1];
st[j+1]=temp;}}}
}
想问问各位铁铁好兄弟,为啥创建的文件044.txt里面啥都没有呢,本意是想将stu1.txt中数据(结构体)进行整体交换排序,现在VC下跑起来0error,0warning。看了好几遍都没看出来,哪位铁汁给讲讲