#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]; int 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, рядка swap strcpy(*(p+pos),*(p+i)); strcpy(*(p+i),str);
}
}
//总结:
/*二维数组表示(行地址,列地址) Вказівник проходить по масиву 2D масив символів (адреса рядка, адреса стовпця) */
|