bsearch_s函数的演示下面是一个使用 bsearch_s 的示例代码:#include <stdlib.h>#include <stdio.h>#include <search.h>#include <string.h>int comp(void* context, char** str1, char** str2){char* s1 = *str1;char* s2 = *str2;return strcmp(s1, s2);}int main(void){char* arr[] = {...
The bsearch_s function performs a binary search of a sorted array of num elements, each of width bytes in size. The base value is a pointer to the base of the array to be searched, and key is the value being sought. The compare parameter is a pointer to a user-supplied routine that...
同所有边界检查函数,bsearch_s(及对应的泛型宏)(C23 起),仅若实现定义__STDC_LIB_EXT1__且用户在包含<stdlib.h>前定义__STDC_WANT_LIB_EXT1__为整数常量 1 才保证可用。 3,4)分别等价于(1)与(2)的泛型宏。令T为一个无限定的对象类型(包括void)。
C库函数void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *))函数搜索nitems对象的数组,初始成员对于与key指向的对象匹配的成员,由base指向。 数组的每个成员的size由size指定。 根据compar引用的比较函数,数组的内容应按升序排序。
void *bsearch_s( const void *key, const void *base, size_t num, size_t width, int ( __cdecl *compare ) ( void *, const void *key, const void *datum), void * context ); Return Value bsearch_s returns a pointer to an occurrence ofkey in the array pointed to by base. If key...
void *bsearch_s( const void *key, const void *base, size_t num, size_t width, int ( __cdecl *compare ) ( void *, const void *key, const void *datum), void * context ); Parameters key Object to search for. base Pointer to base of search data. ...