Listing 1 Sorts command-line arguments with qsort

/* sortargs.c:                 *
 *Sorts command-line arguments */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int comp(const void *, const void *);

main(int argc, char *argv[])
{
    qsort (argv+1,argc-1,
          sizeof argv[0],comp);
    while (--argc)
        puts(*++argv);
    return 0;
}

int comp(const void *p1, const void *p2)
{
    const char *ps1 = * (char **) p1;
    const char *ps2 = * (char **) p2;

    return strcmp(ps1,ps2);
}

/* OUTPUT of the command "sortargs *.c"
CLOCK.C
MENU.C
PSCREEN.C
SORTARGS.C
STACK.C
STACK1.C
STACK2.C
STACK3.C
STACK4.C
TCLOCK.C
TEST2.C
TSTACK.C
TSTACK2.C
TSTACK3.C
TSTACK4.C
*/
/* End of File */