#include #include #include #define TRUE 0 #define FALSE -1 void main(void){ int i, len, pass, size; char ary[3][5], name[5], hold[5]; printf("** TESTSORT **\n"); getchar(); memset(ary, 0, sizeof(ary)); strcpy(ary[0], "A002"); strcpy(ary[1], "A003"); strcpy(ary[2], "A001"); size = 4; for(pass = 1; pass<=size-1; pass++){/*for-loop*/ for(i = 0; i<=size-2; i++){/*sub-loop*/ len = strlen(ary[i]); if(strncmp(ary[i], ary[i+1], len) > 0){/* ŒðŠ· */ len = strlen(ary[i]); memcpy(hold, ary[i], len); hold[len] = 0x00; len = strlen(ary[i+1]); memcpy(ary[i], ary[i+1], len); ary[i][len] = 0x00; len = strlen(hold); memcpy(ary[i+1], hold, len); ary[i+1][len] = 0x00; }/* ŒðŠ· */ }/*sub-loop*/ }/*for-loop*/ for(i = 0; i<3; i++){ memcpy(name, ary[i], 4); name[4] = 0x00; printf("ary[%d] = %s\n", i, name); } getchar(); }