1 #define _CRT_SECURE_NO_WARNINGS 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 6 void print_Num(char myArray[10][30],int num) 7 { 8 int i = 0; 9 for (; i < num; i++) 10 { 11 printf("%s ",myArray[i]); 12 } 13 } 14 void sort_Num1(char array[10][30],int num) 15 { 16 int i = 0,j=0; 17 char mybuf[30]; 18 for (i = 0; i < num; i++) 19 { 20 for (j = i + 1; j < num; j++) 21 { 22 if (strcmp(array[i], array[j])>0) 23 { 24 strcpy(mybuf, array[j]); 25 strcpy(array[j], array[i]); 26 strcpy(array[i], mybuf); 27 } 28 } 29 } 30 } 31 32 int main() 33 { 34 int i = 0, j = 0; 35 int num = 5; 36 char mybuf[30]; 37 char array[10][30] = {"aaaa","dddd","aac","bbbb","1121213"}; 38 39 //編譯器只關心:10行,30列,array+1,跳30個; 40 /*int len1 = sizeof(array); 41 int len2 = sizeof(array[0]); 42 int num1 = len1 / len2; 43 printf("%d %d %d\n", len1, len2, num1);*/ 44 printf("排序前:\n"); 45 print_Num(array, num); 46 sort_Num1(array, num); 47 printf("排序後:\n"); 48 print_Num(array, num); 49 50 system("pause"); 51 return 0; 52 }