Contents|Index|Previous|Next

qsort
[sort an array]

    SYNOPSIS
    #include <stdlib.h>
    void qsort(void *base, size_t nmemb, size_t size,
                    int (*compar)(const void *, const void *) );

DESCRIPTION
qsort sorts an array (beginning at base) of nmemb objects. size describes the size of each element of the array.

You must supply a pointer to a comparison function, using the argument shown as compar. (This permits sorting objects of unknown properties.) Define the comparison function to accept two arguments, each a pointer to an element of the array starting at base. The result of (*compar) must be negative if the first argument is less than the second, zero if the two arguments match, and positive if the first argument is greater than the second (where “less than” and “greater than” refer to whatever arbitrary ordering is appropriate).

The array is sorted in place; that is, when qsort returns, the array elements, beginning at base, have been reordered.

RETURNS
qsort does not return a result.

COMPLIANCE
qsort meets ANSI standards (without specifying the sorting algorithm).