Created
April 7, 2014 19:46
-
-
Save merbussa/10038914 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> | |
static int | |
cmpstringp(const void *p1, const void *p2) | |
{ | |
/* The actual arguments to this function are "pointers to | |
pointers to char", but strcmp(3) arguments are "pointers | |
to char", hence the following cast plus dereference */ | |
return strcmp(* (char * const *) p1, * (char * const *) p2); | |
} | |
int | |
main(int argc, char *argv[]) | |
{ | |
int j; | |
if (argc < 2) { | |
fprintf(stderr, "Usage: %s <string>...\n", argv[0]); | |
exit(EXIT_FAILURE); | |
} | |
qsort(&argv[1], argc - 1, sizeof(argv[1]), cmpstringp); | |
for (j = 1; j < argc; j++) | |
puts(argv[j]); | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment