
#include <stdioh>
#include <stringh>
const int MAXLEN = 100;
const int MAXSIZE = 10;
void sort(char title[][MAXLEN],int n) {//排序
int i,j,k;
char tstr[MAXLEN];
for(i = 0; i < n - 1; ++i) {
k = i;
for(j = i + 1; j < n; ++j) {
if(strcmp(title[k],title[j]) > 0)
k = j;
}
if(k != i) {
strcpy(tstr,title[k]);
strcpy(title[k],title[i]);
strcpy(title[i],tstr);
}
}
}
void show(char s[][MAXLEN],int n) {
int i;
for(i = 0; i < n; ++i)
printf("%s",s[i]);
puts(" ");
}
int main(void) {
char s[MAXSIZE][MAXLEN];
int i;
for(i = 0; i < MAXSIZE; ++i) {
printf("string(%02d/%d):",i + 1,MAXSIZE);
fgets(s[i],MAXLEN,stdin);
}
printf("排序前:\n");
show(s,MAXSIZE);
sort(s,MAXSIZE);
printf("排序后:\n");
show(s,MAXSIZE);
return 0;
}
以上就是关于C语言编程解决字符串数组字典排序全部的内容,包括:C语言编程解决字符串数组字典排序、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)