/*1、定义二维字符数组 char arr[5][20]={ "heima","itcast","TingHua","Peking","shuangYuan"}; 将其排序后输出。 */ #include <stdio.h> #include <string.h>
int main(int argc, const char * argv[]) { char arr[5][20]={ "heima","itcast","TingHua","Peking","shuangYuan"}; char temp[20]={0}; for (int i=0; i<5-1; i++) { for (int j=0; j<5-i-1; j++) { if(strcmp(arr[j],arr[j+1])>0){ strcpy(temp, arr[j]); strcpy(arr[j], arr[j+1]); strcpy(arr[j+1], temp); } } } for (int i=0; i<5; i++) { printf("%s\t",arr); } return 0; }
|