问题遇到的现象和发生背景
```bash
struct address
{
char name[20];
int year,month,date;
char tel[12];
char addr[40];
};
sort(struct address book[],int n)
{
int i,j,k;
struct address temp;
for(i=0;i<n-1;i++){
k=i;
for(j=i+1;j<n;j++){
if(book[j].year>book[k].year)
{k=j;
}
if(book[j].year==book[k].year&&book[j].month>book[k].month)
{k=j;
}
if(book[j].year==book[k].year&&book[j].month==book[k].month&&book[j].date>book[k].date)
{k=j;
}
}
if(k!=j){
temp=book[i];
book[i]=book[k];
book[k]=temp;
}
for(i=0;i<n;i++){
printf("%d\n",i+1);
printf("Name:%s",book[i].name);
printf("Birthday:%d-%d-%d\n",book[i].year,book[i].month,book[i].date);
printf("Tel:%s\n",book[i].tel);
printf("Address:%s",book[i].addr);
}
}
}
#include<stdio.h>
int main()
{int i,n;
struct address b[100];
printf("Input n:");
printf("成功运行");
scanf("%d",&n);
printf("%d",n+1);
printf("Input information\n");
for(i=0;i<n;i++){
scanf("%s%d%d%d%s%s,b[i].name,&b[i].year,&b[i].month,&b[i].date,b[i].tel,b[i].addr");
}
sort(b,n);
return 0;
}
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果