LabWindows/CVI

Content Type
Programming Language
Current manual
Table of Contents

bsearch

bsearch

void *bsearch (const void *keyToFind, const void *baseArrayElement, size_t numberOfElements, size_t elementSize, int (*comparisonFunction)(const void *, const void *));

Purpose

Searches an array of objects for an element that matches a specified key. The array must already be sorted in ascending order.

Parameters

Input
Name Type Description
keyToFind const void * The key element to find in the array.
baseArrayElement const void * The array to be searched. number_ofElements specifies the number of elements in the array. elementSize describes the size of each element in the array.
numberOfElements size_t Specifies the number of elements in the array.
elementSize size_t The size in bytes of each element in the array.
comparisonFunction int (*)(const void *, const void *) The name of a function used to compare an element of the array with the key.
  • The form of this comparison function must be:

    int compar(const void *key, const void *data);
  • This comparison function must return the following values:
    If the key is... the comparison function returns...
    Less than the array element Less than zero
    Equal to the array element Zero
    Greater than the array element Greater than zero

Return Value

Name Type Description
matchingElement void * A pointer to the matching element of the array or a null pointer if no match is found. If two elements compare as equal, the element that is matched is unspecified.

Additional Information

Library: ANSI C Library

Include file: ansi_c.h

LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later

Was this information helpful?