home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_11_04
/
1104108b
< prev
next >
Wrap
Text File
|
1993-02-05
|
668b
|
39 lines
/* sort2.c: Sort strings in descending order */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NELEMS 4
static int scomp(const void *, const void *);
main()
{
size_t i;
char *some_strings[NELEMS] =
{"well","hello","you","rascal"};
qsort(some_strings, NELEMS, sizeof some_strings[0], scomp);
for (i = 0; i < NELEMS; ++i)
puts(some_strings[i]);
return 0;
}
static int scomp(const void *p1, const void *p2)
{
char *a = * (char **) p1;
char *b = * (char **) p2;
/* Negate for descending order */
return -strcmp(a,b);
}
/* Output:
you
well
rascal
hello
*/