结构体应用方面不知道哪出错了
一个班有5名学生,学生信息包括姓名,年龄家庭住址等,按姓名升序进行输出#include<stdio.h>
#include<string.h>
struct user_info
{
char name[20];
int age;
char phone[20];
char address[80];
};
void main()
{
int i,j,k;
struct user_info tmp;
struct user_info user[5]={{"li",31,"1258764","beijing"},
{"zhao",39,"5897412","shanghai"},
{"qian",28,"3654879","chongqing"},
{"zhou",30,"5632146","hangzhou"},
{"sun",34,"8532541","shenyang"}
};
for(i=1;i<5;i++)
{
k=5-i;
for(j=0;j<5-i;j++)
if(strcmp(user[j].name,user[k].name)>0)
k=j;
if(k!=5-i)
{
tmp=user[k];
user[k]=user[5-i];
user[5-i]=tmp;
}
}
printf("%20s%5s%15s%20s","name","age","phonge","address");
printf("\n");
for(i=0;i<5;i++)
printf("%20s%5s%15s%20s\n",user[i].name,user[i].age,user[i].phone,user[i].address);