NAME

bsearch - binary search a sorted table

SYNOPSIS

#include "zkStdlib.h"

void *bsearch(const void *key, const void *base, size_t nel,
    size_t width, int (*compar)(const void *, const void *));

DESCRIPTION

The bsearch() function searches an array of nel objects, the initial element of which is pointed to by base, for an element that matches the object pointed to by key. The size of each element in the array is specified by width.

The comparison function pointed to by compar is called with two arguments that point to the key object and to an array element, in that order.

The function must return an integer less than, equal to, or greater than 0 if the key object is considered, respectively, to be less than, to match, or to be greater than the array element. The array must consist of: all the elements that compare less than, all the elements that compare equal to, and all the elements that compare greater than the key object, in that order.

RETURN VALUE

The bsearch() function returns a pointer to a matching member of the array, or NULL if no match is found. If two or more members compare equal, which member is returned is unspecified.

ERRORS

No errors are defined.