#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 학생들[3][20]; 지능 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)는 행 주소가 될 수 없으며, 반드시 1차 배열의 첫 번째 주소인 열 주소여야 합니다 {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 문자 배열(행 주소, 열 주소) */
|