#include <stdlib.h> void *bsearch(const void *srch, const void *blk, size_t n, size_t size, int (*cmp)(const void *, const void *));
bsearch
scans a sorted memory block addressed by blk
for a
match with a search value addressed by srch
. The blk
function is a pointer
to the first element of the memory block to be scanned. n
designates the number of elements in the block, and size
is the
size of each element in bytes.
bsearch
calls a user-provided comparison function, cmp
,
and passes cmp
pointers to the two objects being compared.
cmp
must return the following values:
The description of qsort
discusses
comparison function requirements in more detail.
bsearch
returns a pointer to the element that matches the search
value. If no match can be found, NULL
is returned.
qsort
.
qsort