[C] 纯文本查看 复制代码#include "stdio.h"
#include "string.h"
struct student {
char name[20];
char tel[12];
};
void sort(student ss[]);
void outPut(student ss[]);
int main()
{
student contacts[10] = { {"LiLei","13678941562"},
{"WangHao","15046523182"},
{"WangDi","13598741863"},
{"OuyangDan","13875469871"},
{"HanLi","13647152364"},
{"Zhengchao","15098563214"},
{"Futong","13213254698"},
{"FangYang","15978632132"},
{"BaiHao","15432145698"},
{"Cenyu","15896566532"} };
sort(contacts);
outPut(contacts);
return 0;
}
void sort(struct student ss[])
{
int i,j;
student temp;
for (i = 0; i < 10 - 1; ++i)
for (j = i + 1; j < 10; ++j)
{
if (ss[i].name[0] >= ss[j].name[0]) {
temp = ss[i];
ss[i] = ss[j];
ss[j] = temp;
}
}
}
void outPut(struct student ss[])
{
int i;
printf("------通讯录-------\n");
printf("姓名\t\t电话\t\n");
for (i = 0; i < 10; i++)
printf("%s\t\t%s\t\n",ss[i].name,ss[i].tel);
printf("\n");
}