void *bsearch (const void *key, const void *base, size_t nmemb, size_t size, long (*compar)(const void *, const void *));
void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
base Pointer to a table to be searched
nmemb Number of members to be searched
size Number of bytes of a member to be searched
compar Pointer to a function that performs comparison
If a matching member is found: Pointer to the matching member
If no matching member is found: NULL
The bsearch function searches the table specified by base for a member that matches the data specified by key, by binary search method. The function that performs comparison should receive pointers p1 (first parameter) and p2 (second parameter) to two data items to compare, and return the result complying with the specification below.
*p1 < *p2: Returns a negative value.
*p1 > *p2: Returns a positive value.
Members to be searched must be placed in the ascending order.