bsearch.c

The libc implementation

Author

Martin ‘Solar’ Baute

License

Public Domain

Summary
bsearch.cThe libc implementation
Functions
bsearchPerforms a binary search inside an array of nmemb itens of size bytes

Functions

bsearch

void * bsearch(const void *key,
const void *base,
size_t nmemb,
size_t size,
int (*compar)( const void *, const void * ))

Performs a binary search inside an array of nmemb itens of size bytes

keya pointer to the data to compare to
basethe offset of the array
nmembthe amount of objects in the array
sizethe size of each object in the array
compara pointer to a function that compares the key and an element in the array

Returns a pointer to the found element

Returns NULL if there is no element found

void * bsearch(const void *key,
const void *base,
size_t nmemb,
size_t size,
int (*compar)( const void *, const void * ))
Performs a binary search inside an array of nmemb itens of size bytes