| 1 | .\" Copyright (c) 1990 The Regents of the University of California. |
| 2 | .\" All rights reserved. |
| 3 | .\" |
| 4 | .\" %sccs.include.redist.man% |
| 5 | .\" |
| 6 | .\" @(#)bsearch.3 5.3 (Berkeley) %G% |
| 7 | .\" |
| 8 | .TH BSEARCH 3 "" |
| 9 | .UC 7 |
| 10 | .SH NAME |
| 11 | bsearch - binary search of a sorted table |
| 12 | .SH SYNOPSIS |
| 13 | .nf |
| 14 | .ft B |
| 15 | #include <stdlib.h> |
| 16 | .sp |
| 17 | char * |
| 18 | bsearch(const void *key, const void *base, |
| 19 | size_t nmemb, size_t size, |
| 20 | int (*compar) (const void *, const void *)); |
| 21 | .ft R |
| 22 | .fi |
| 23 | .SH DESCRIPTION |
| 24 | The |
| 25 | .I bsearch |
| 26 | function searches an array of |
| 27 | .I nmemb |
| 28 | objects, the inital member of which is |
| 29 | pointed to by |
| 30 | .IR base , |
| 31 | for a member that matches the object pointed to by |
| 32 | .IR key . |
| 33 | The size of each member of the array is specified by |
| 34 | .I size . |
| 35 | .PP |
| 36 | The contents of the array should be in ascending sorted order according |
| 37 | to the comparison function referenced by |
| 38 | .IR compar . |
| 39 | .I Compar |
| 40 | is called with two arguments that point to the |
| 41 | .I key |
| 42 | object and to an array member, in that order, and must return an integer |
| 43 | less than, equal to, or greater than zero if the |
| 44 | .I key |
| 45 | object is considered, respectively, to be less than, equal to, or to |
| 46 | greater than the array member. |
| 47 | .PP |
| 48 | The |
| 49 | .I bsearch |
| 50 | function returns a pointer to a matching member of the array, or a null |
| 51 | pointer if no match is found. |
| 52 | If two members compare as equal, which member is matched is unspecified. |
| 53 | .SH "SEE ALSO" |
| 54 | db(3), lsearch(3), qsort(3) |
| 55 | .SH STANDARDS |
| 56 | .B Bsearch |
| 57 | conforms to ANSI X3.159-1989 (``ANSI C''). |