bsearch()

perform binary search of table 

Function


SYNOPSIS

#include <stdlib.h>

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


DESCRIPTION

The bsearch() function is a binary search routine that returns a pointer into a table (an array) indicating where an element may be found. If an element cannot be found, it returns a null pointer.

The table must be previously sorted in increasing order according to a comparison function pointed to by compar. This routine is called with two arguments, the pointers to the elements being compared. It returns an integer less than, equal to, or greater than 0, according to whether the first argument is to be considered less than, equal to, or greater than the second argument. The comparison function need not compare every byte, so arbitrary data may be contained in the elements in addition to the values being compared.


PARAMETERS

key 

Specifies the data you are searching for in the table.

base 

Points to the element at the base of the table.

nel 

Is the number of elements in the table.

size 

Is the number of bytes in each element.

compar 

Specifies the comparator function.


RETURN VALUES

If the key cannot be found in the table, the bsearch() function returns a null pointer, otherwise returns a pointer to a matching element of the array.


CONFORMANCE

ANSI/ISO 9899-1990


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
hsearch(), lsearch(), qsort(), tsearch()


PTC MKS Toolkit 10.4 Documentation Build 39.