#include <stdio.h> #include <string.h> //用指向指針的指針的方法對5個字符串排序並輸出。 int main(){ void sort(char * pstr[5]); int i; char str[5][50]={"asdfadsf","oiuyoiuy","lkwjerht","uytr","qoiurty"}; char * pstr[5]; printf("排序前:\n"); for(i=0; i<5; i++){ pstr[i]=str[i]; printf("%s\n",pstr[i]); } //對字符串排序 sort(pstr); printf("排序后:\n"); for(i=0; i<5; i++){ printf("%s\n",pstr[i]); } return 0; } void sort(char * pstr[5]){ char * t; int i,j; for(i=0; i<5; i++){ for(j=i+1; j<5; j++){ if(strcmp(pstr[i],pstr[j]) > 0) { t=pstr[j]; pstr[j]=pstr[i]; pstr[i]=t; } } } }