home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_11_04
/
1104108a
< prev
next >
Wrap
Text File
|
1993-02-05
|
548b
|
36 lines
/* sort1.c: Sort integers with qsort() */
#include <stdio.h>
#include <stdlib.h>
#define NELEMS 4
static int icomp(const void *, const void *);
main()
{
size_t i;
int some_ints[NELEMS] = {40, 12, 37, 15};
qsort(some_ints,NELEMS,sizeof some_ints[0], icomp);
for (i = 0; i < NELEMS; ++i)
printf("%d\n",some_ints[i]);
return 0;
}
static int icomp(const void *p1, const void *p2)
{
int a = * (int *) p1;
int b = * (int *) p2;
return a - b;
}
/* Output:
12
15
37
40
*/