#include 「stdafx.h」 #include 「stdio.h」 虚空out_student(char (*p)[20],int n); char (*p)[20]Data ポインタ(行ポインタ) 虚sort_student(char (*p)[20],int n); int main() {char students[3][20]; INT I; for(i=0; i<3; i++) scanf("%s",*(students+i)); エントリー out_student(学生3名); sort_student(学生3名); out_student(学生3名); 返す0;
} void out_student(char (*p)[20],int n) //(*p) 行アドレス {int i; for(i=0; i<n; i++) printf("%s",*(p+i)); printf("\n");
}
//选择排序 虚空sort_student(char (*p)[20],int n) {int i,j; for(i=0; i<n-1; i++) {int pos=i; for(j=i+1; J<n; j++) {if(strcmp(*(p+j),*(p+pos)<0)) //strcmp(*(p+j),*(p+pos)<0) *(p+j) は行アドレスではなく、一階配列の最初のアドレスである列アドレスでなければなりません {pos=j; }
}
} if(pos!=i) {char str[20]={'\0'}; strcpy(str,*(p+pos)); *(p+pos) pos行の最初の列のアドレス、すなわちスワップ文字列 strcpy(*(p+pos),*(p+i)); strcpy(*(p+i),str);
}
}
//总结:
/*二维数组表示(行地址,列地址) ポインタは配列を通過します 2D文字配列(行アドレス、列アドレス)*/
|