qsort, qsort_r − sort an array
qsort(void *base, size_t nmemb,
int (*compar)(const void *, const void *));
qsort_r(void *base, size_t
nmemb, size_t size,
int (*compar)(const void *, const void *, void *),
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
The qsort() function sorts an array with nmemb elements of size size. The base argument points to the start of the array.
The contents of the array are sorted in ascending order according to a comparison function pointed to by compar, which is called with two arguments that point to the objects being compared.
The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. If two members compare as equal, their order in the sorted array is undefined.
The qsort_r() function is identical to qsort() except that the comparison function compar takes a third argument. A pointer is passed to the comparison function via arg. In this way, the comparison function does not need to use global variables to pass through arbitrary arguments, and is therefore reentrant and safe to use in threads.
The qsort() and qsort_r() functions return no value.
qsort_r() was added to glibc in version 2.8.
The qsort() function conforms to SVr4, 4.3BSD, C89, C99.
Library routines suitable for use as the compar argument to qsort() include alphasort(3) and versionsort(3). To compare C strings, the comparison function can call strcmp(3), as shown in the example below.
For one example of use, see the example under bsearch(3).
Another example is the following program, which sorts the strings given in its command-line arguments:
cmpstringp(const void *p1, const void *p2)
/* The actual arguments to this function are "pointers to
pointers to char", but strcmp(3) arguments are "pointers
to char", hence the following cast plus dereference */
(char * const *) p1, * (char * const *) p2);
main(int argc, char *argv)
if (argc <
fprintf(stderr, "Usage: %s <string>...\n", argv);
qsort(&argv, argc − 1, sizeof(char *), cmpstringp);
for (j = 1; j
< argc; j++)
sort(1), alphasort(3), strcmp(3), versionsort(3)
This page is part of release 3.69 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at http://www.kernel.org/doc/man−pages/.
More Linux Commands
wgetdelay(3ncurses) curses window properties (Man Page).....
This implementation provides functions which return properties set in the WINDOW structure, allowing it to be opaque if the symbol NCURSES_OPAQUE is defined: is
derwin(3ncurses) - create curses windows - Linux man page...
Calling newwin creates and returns a pointer to a new window with the given number of lines and columns. The upper left-hand corner of the window is at line beg
XkbResizeKeySyms(3) - Change the number of symbols bound to
XkbResizeKeySyms reserves the space needed for needed keysyms and returns a pointer to the beginning of the new array that holds the keysyms. It adjusts the off
gets(3) - input of characters and strings - Linux man page
Never use this function. gets() reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF, which it replaces with a null
mev(1) - a program to report mouse events - Linux man page
The mev program is part of the gpm package. The information below is extracted from the texinfo file, which is the preferred source of information. The mev prog
xdg-user-dir(1) Find an XDG user dir - Linux manual page....
xdg-user-dir looks up the current path for one of the special XDG user dirs. This command expects the name of an XDG user dir as argument. The possible names ar
rake(1) Ruby Make (Commands - Linux manual page)............
Rake is a simple ruby(1) build program with capabilities similar to the regular make(1) command. Rake has the following features: * Rakefiles (Rakes version of
Tcl_GetIntFromObj(3) - manipulate Tcl objects as integer val
These procedures are used to create, modify, and read Tcl objects that &#9474; hold integral values. &#9474; The different routines exist to accommodate differe
curl(1) - transfer a URL (Commands - Linux manual page).....
curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS,
syscall(2) - indirect system call - Linux manual page.......
syscall() is a small library function that invokes the system call whose assembly language interface has the specified number with the specified arguments. Empl
nmcli-examples(5) usage examples of nmcli - Linux man page
nmcli is a command-line client for NetworkManager. It allows controlling NetworkManager and reporting its status. For more information please refer to nmcli(1)
Tk_FreeCursorFromObj(3) - maintain database of cursors......
These procedures manage a collection of cursors being used by an application. The procedures allow cursors to be re-used efficiently, thereby avoiding server ov