#include <stdio.h> #include <string.h> #define N 5 #define COL 100 void bubble_sort(char (*TestA)[100],int count) { char j = 0; char i = 0; char flag = 0; char temp[100]; for (i = 0;i<count -1;i++) { flag = 0; for (j = i;j<count -1 -i;j++) { if (strcmp(TestA[j],TestA[j+1])>0) { strcpy(temp,TestA[j]); strcpy(TestA[j],TestA[j+1]); strcpy(TestA[j+1],temp); flag = 1; } } if (flag == 0) { break; } } } void main() { char test[N][100]; char i = 0; for (i = 0;i<N;i++) { gets(test[i]); } for (i = 0;i<N;i++) { printf("test[%d]:%s/n",i,test[i]); } printf("/nafter sorted/n/n"); bubble_sort(test,N); for (i = 0;i<N;i++) { printf("test[%d]:%s/n",i,test[i]); } }