Download pSOSystem System Calls

Transcript
pREPC+ System Calls
bsearch
bsearch
Searches an array.
#include <stdlib.h>
void *bsearch(
const void *key,
/* search key */
const void *base,
/* start point */
size_t nmemb,
/* number of members */
size_t size,
/* member size */
int (*compar)(const void *, const void *)
/* comparison operator */
)
3
Description
The bsearch() function searches an array of nmemb 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 of the array is specified by size.
The array must be sorted in ascending order. A user supplied comparison function,
compar, is called by bsearch with two arguments. The first argument to compar is
a pointer to the key object, and the second is a pointer to an array member. The
compar function must return an integer that is either less than, equal to, or greater
than zero if key object is considered, respectively, to be less than, equal to, or
greater than the array member.
Arguments
key
Points to the object to be matched in the search.
base
Points to the beginning of the array to be searched.
nmemb
Specifies the number of members in the array.
size
Specifies the size of each member in the array.
Return Value
This function returns a pointer to the first matching member detected. If no match
is found, it returns a null pointer. In the event of an error, errno is set to indicate
the condition.
pSOSystem System Calls
3-15