#include <stdio.h>
#include <stdlib.h>
struct node
{
char id[100];
char name[20];
int year;
int month;
int day;
double ton;
char city[80];
}log[1005];
int count;
int cmp(const void *a , const void *b)
{
node * c = (node *) a;
node * d = (node *) b;
if(c -> year != d -> year)
return (c->year) - (d->year);
if(c -> month != d -> month)
return (c->month) - (d->month);
return (c->day) - (d->day);
}
int loadfile()
{
FILE *fp = NULL;
fp = fopen("file15.txt","r");
if(fp == NULL)
{
printf("load file15.txt error!\n");
return -1;
}
count = 0;
while(!feof(fp))
{
fscanf(fp , "%s %s %d-%d-%d %lf %s",log[count].id,log[count].name,log[count].year,log[count].month,log[count].day,log[count].ton,log[count].city);
count ++;
}
return 0;
}
void output()
{
int i;
for(i=0;i<count;i++)
{
printf("%s\t%s\t%d-%d-%d\t%lf\t%s\n",log[i].id,log[i].name,log[i].year,log[i].month,log[i].day,log[i].ton,log[i].city);
}
}
int main()
{
loadfile();
qsort(log,count,sizeof(node),cmp);
output();
return 0;
}
注释和菜单栏你自己加吧,主要的部分给你写了,菜单栏就直接printf 和 scanf完成就可以
追问代码运行闪一下就退出了。output里printf打不出来啊
追答你.c文件的同级目录下有没有file15.txt文件?
追问有的,我改到了e里换了打开目录还是不行。