羡慕那些会玩指针的
程序代码:
#include<stdio.h> #include<string.h> void sort(char *a[], int n) { int i, j, m; char **p, *t; p = a; for (i = 0; i < n - 1; i++) { m = i; for (j = i + 1; j < n; j++) if (strcmp(p[m], p[j]) > 0) m = j; if (i != m) { t = p[i]; p[i] = p[m]; p[m] = t; } } } void print(char *a[], int n) { int i; char **p; p = a; for (i = 0; i < n; i++) printf("%s\n", p[i]); } int main() { void sort(char *a[], int n); void print(char *a[], int n); char *a[5] = { "hello","you","want","eat","something" }; char **p; p = a; sort(p, 5); print(p, 5); return 0; }