![]() Chapter Contents |
![]() Previous |
![]() Next |
| bsearch |
| Portability: | ISO/ANSI C conforming, UNIX compatible |
| SYNOPSIS | |
| DESCRIPTION | |
| RETURN VALUE | |
| EXAMPLE | |
| RELATED FUNCTIONS | |
| SEE ALSO |
| SYNOPSIS |
#include <stdlib.h>
void *bsearch(const void *srch, const void *blk,
size_t n, size_t size,
int (*cmp)(const void *, const void *));
| DESCRIPTION |
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.
| RETURN VALUE |
bsearch
returns a pointer to the element that matches the search value. If no match
can be found,
NULL
is returned.
| EXAMPLE |
See the example section for qsort.
| RELATED FUNCTIONS |
| SEE ALSO |
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.