


      BSEARCH(3C)                 (UNIX 5.0)                BSEARCH(3C)



      NAME
           bsearch - binary search

      SYNTAX
           char *bsearch ((char *) key, (char *) base, nel, sizeof
           (*key), compar)
           unsigned nel;
           int (*compar)( );

      DESCRIPTION
           Bsearch is a binary search routine generalized from Knuth
           (6.2.1) Algorithm B.  It returns a pointer into a table
           indicating where a datum may be found.  The table must be
           previously sorted in increasing order according to a
           provided comparison function.  Key points to the datum to be
           sought in the table.  Base points to the element at the base
           of the table.  Nel is the number of elements in the table.
           Compar is the name of the comparison function, which is
           called with two arguments that point to the elements being
           compared.  The function must return an integer less than,
           equal to, or greater than zero according as the first
           argument is to be considered less than, equal to, or greater
           than the second.

      DIAGNOSTICS
           A NULL pointer is returned if the key cannot be found in the
           table.

      NOTES
           The pointers to the key and the element at the base of the
           table should be of type pointer-to-element, and cast to type
           pointer-to-character.
           The comparison function need not compare every byte, so
           arbitrary data may be contained in the elements in addition
           to the values being compared.
           Although declared as type pointer-to-character, the value
           returned should be cast into type pointer-to-element.

      SEE ALSO
           lsearch(3C), hsearch(3C), qsort(3C), tsearch(3C).















      Page 1                                         (73 A2 02MTA REV1)



