Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

OSS Library Calls (n - r) qsort(3)
NAME
qsort - Sorts a table in place
LIBRARY
G-series native Guardian processes: $SYSTEM.SYSnn.ZCRTLSRL
G-series native OSS processes: /G/system/sysnn/zcrtlsrl
H-series and J-series native Guardian processes: $SYSTEM.ZDLLnnn.ZCRTLDLL
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zcrtldll
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/ycrtldll
SYNOPSIS
#include <stdlib.h>
void qsort (
void *base,
size_t nmemb,
size_t size,
int (*compar)(const void *, const void *));
PARAMETERS
base Points to the first entry in the table.
nmemb Specifies the number of entries in the table.
size Specifies the size in bytes of each table entry.
compar Points to the user-specied function to be used to compare pairs of table ele-
ments. The comparison function will be called with two parameters that point to
the two elements to be compared. The comparison function must return an
integer less than, equal to, or greater than 0 (zero), depending on whether the first
element in the comparison is considered less than, equal to, or greater than the
second element.
DESCRIPTION
The qsort( ) function sorts a table having a specified number of entries. The contents of the table
are sorted in ascending order according to a user-specified comparison function (the strcmp( )
function, for example).
NOTES
The qsort( ) function is reentrant, but care should be taken to ensure that the function supplied as
argument compar is also reentrant.
The comparison function need not compare every byte, so arbitrary data may be contained in the
elements in addition to the values being compared.
When two members compare as equal, their order in the sorted array is indeterminate.
EXAMPLE
If a two-dimensional character array (an array of equal-length character strings) is declared as:
#define NUMBER_OF_STRINGS 5
#define LENGTH_OF_STRINGS 80
char table_string [NUMBER_OF_STRINGS] [LENGTH_OF_STRINGS];
The array can be sorted through the call:
#include <stdlib.h>
#include <string.h>
qsort (table_string, NUMBER_OF_STRINGS, LENGTH_OF_STRINGS, strcmp);
because the conventions recognized by qsort( ) are those used by strcmp( ) to return values.
527187-017 Hewlett-Packard Company 5129