#include "stdafx.h" #include "stdio.h" void out_student(char (*p)[20],int n); char (*p)[20]Указател на данни (указател на ред) void sort_student(Char (*p)[20],int n); int main() {char students[3][20]; интелект i; for(i=0; i<3; i++) scanf("%s",*(students+i)); Записани out_student(студенти,3); sort_student(студенти,3); out_student(студенти,3); return 0;
} void out_student(char (*p)[20],int n) //(*p) адрес на линия {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) не може да е адрес на ред, той трябва да е адрес на колона, първият адрес на масив от първи ред {pos=j; }
}
} if(pos!=i) {char str[20]={'\0'}; strcpy(str,*(p+pos)); *(p+pos) Адресът на първата колона на pos линията, string за swap strcpy(*(p+pos),*(p+i)); strcpy(*(p+i),str);
}
}
//总结:
/*二维数组表示(行地址,列地址) Показалецът преминава през масива 2D масив от символи (адрес на ред, адрес на колона) */
|