Created
October 21, 2011 18:34
-
-
Save iwinux/1304584 to your computer and use it in GitHub Desktop.
字符串字典排序
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define M 6 | |
#define N 5 | |
/* reverse strcmp to get descending sort */ | |
int cmp(char *s1, char *s2) { | |
return -strcmp(s1, s2); | |
} | |
int main(int argc, char *argv[]) { | |
int i; | |
char strings[M][N]; | |
for (i = 0; i < M; i++) { | |
scanf("%s", &strings[i]); | |
} | |
/* reference: http://www.codecogs.com/reference/c/stdlib.h/qsort.php */ | |
qsort(strings, M, N, cmp); | |
printf("The result is:\n"); | |
for (i = 0; i < M; i++) { | |
printf("%s\n", strings[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment