出入校人员管理系统,要将出校人数降序排列,用了冒泡排序,不知道为什么输出的总是乱码,看不出来程序哪里有问题
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <conio.h>
#define N 10
void A() //按出校时间降序
{
FILE *fp,*fl;
person a[N],c[N];
char temp[20];
int i=0,j,count=0,k,flag=0;
if((fl=fopen("temp2","wb+"))==NULL)
{
printf("文件打开错误!");
}
if((fp=fopen("informations","rb"))==NULL)
{
printf("读取失败,可能是文件不存在,请先录入并保存信息!\n");
//getch();
}
while((fread(&a[i],sizeof(person),1,fp))!=0)
{
if(strcmp(a[i].condition,"out")==0)
{
fwrite(&a[i],sizeof(person),1,fl);
count++;
}
}
if(count==0)
{
printf("无人出校\n");
return;
}
if(count!=0)
{
for (k=0;!feof(fl);k++)
{
fread(&c[k],sizeof(person),1,fl);
}
for(k=0;k<count-1;k++)
{
flag=0;
for (j=0;j<count-1-k;j++)
{
if(strcmp(c[j].day,c[j+1].day)<0)
{
strcpy(temp,c[j].day);
strcpy(c[j].day,c[j+1].day);
strcpy(c[j+1].day,temp);
flag=1;
}
}
if(flag==0)
break;
}
printf("\n序号 身份 身份证号 姓名 联系方式 状态 日期 时间\n");
for(k=0;k<count;k++)
{
printf("%s %5s %s %4s %s %s %5s %5s\n",c[k].no,c[k].degree,c[k].ID,c[k].name,c[k].phone,c[k].condition,c[k].day,c[k].time);
}
printf("对出校人员按出校时间进行降序排序成功,信息显示完毕,谢谢使用\n");
}
fclose(fp);
fclose(fl);
}