BSEARCH(3C)
NAME
bsearch − binary search
SYNOPSIS
char ∗bsearch (key, base, nel, width, compar)
char ∗key;
char ∗base;
int nel, width;
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 the location at which a datum may be found. The table must be previously sorted in increasing order. The first argument is a pointer to the datum to be located in the table. The second argument is a pointer to the base of the table. The third is the number of elements in the table. The fourth is the width of an element in bytes. The last is the name of the comparison routine. It is called with two arguments which are pointers to the elements being compared. The routine must return an integer less than, equal to, or greater than 0 according as the first argument is to be considered less than, equal to, or greater than the second.
DIAGNOSTICS
Zero is returned if the key can not be found in the table.