#include "stdafx.h" #include "stdio.h" void out_student(char (*p)[20],int n); char (*p)[20]Ukazatel dat (ukazatel řádku) void sort_student(char (*p)[20],int n); int main() {Char studenti[3][20]; int i; for(i=0; i<3; i++) scanf("%s",*(studenti+i)); Vstup out_student(studenti,3); sort_student(studenti,3); out_student(studenti,3); return 0;
} void out_student(char (*p)[20],int n) //(*p) adresa řádku {int i; for(i=0; i<n; i++) printf("%s",*(p+i)); printf ("\n");
}
//选择排序 void 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) nemůže být adresa řádku, musí být adresou sloupce, první adresou pole prvního řádu {pos=j; }
}
} if(pos!=i) {char str[20]={'\0'}; strcpy(str,*(p+pos)); *(p+pos) Adresa prvního sloupce pos řádku, swap string strcpy(*(p+pos),*(p+i)); strcpy(*(p+i),str);
}
}
//总结:
/*二维数组表示(行地址,列地址) Ukazatel prochází polem 2D pole znaků (adresa řádku, adresa sloupce) */
|