不知道哪里出错了,数组长度定义小了吗?还是说选择法排序哪里出错了,没有进行排序?求解答,感谢
修改如下,供参考:
#include <stdio.h>
#include <string.h>
struct student {
char xm[11];
char bth[9];
char tel[18];
};
int main()
{
int n, i, j;
struct student std[10], tmp;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%s%s%s", std[i].xm, std[i].bth, std[i].tel);
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - 1 - i; j++) {
if (strcmp(std[j].bth, std[j + 1].bth) > 0)
{
tmp = std[j]; std[j] = std[j + 1]; std[j + 1] = tmp;
}
}
}
for (i = 0; i < n; i++)
printf("%s %s %s\n", std[i].xm, std[i].bth, std[i].tel);
return 0;
}