BSEARCH(3) NEWLIB BSEARCH(3)NAME
2.10 `bsearch'--binary search
SYNOPSIS
#include <stdlib.h>
void *bsearch(const void *KEY, const void *BASE,
size_t NMEMB, size_t SIZE,
int (*COMPAR)(const void *, const void *));
DESCRIPTION
`bsearch' searches an array beginning at BASE for any element that
matches KEY, using binary search. NMEMB is the element count of the
array; SIZE is the size of each element.
The array must be sorted in ascending order with respect to the com‐
parison function COMPAR (which you supply as the last argument of
`bsearch').
You must define the comparison function `(*COMPAR)' to have two
arguments; its result 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).
RETURNS
Returns a pointer to an element of ARRAY that matches KEY. If more
than one matching element is available, the result may point to any of
them.
PORTABILITY
`bsearch' is ANSI.
No supporting OS subroutines are required.
SEE ALSObsearch is part of the library. The full documentation for is main‐
tained as a Texinfo manual. If info and are properly installed at your
site, the command
info
will give you access to the complete manual.
NEWLIB April 2010 BSEARCH(3)