#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[]) {
//遍历输入
char ch[6][100];
for (int j=0; j<6; j++) {
printf("请输入第%d个字符串",j);
gets(ch[j]);
}
//指针数组和常量之间的区别
//新建的是指针,原来的数组能再用
char *cha[6] = {ch[0],ch[1],ch[2],ch[3],ch[4],ch[5]};
for (int i = 0; i < 6; i++) {
for (int j = i+1; j<6; j++) {
if (strcmp(cha[i], cha[j])>0) {
char *temp = cha[i];
cha[i] = cha[j];
cha[j] = temp;
}
}
}
//遍历输出
for (int j=0; j<6; j++) {
puts(cha[j]);
}
return 0;
}
|