1.\" Copyright (c) 1990, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)bsearch.3 5.5 (Berkeley) 04/20/91 7.\" 8.Dd 9.Dt BSEARCH 3 10.Os 11.Sh NAME 12.Nm bsearch 13.Nd binary search of a sorted table 14.Sh SYNOPSIS 15.Fd #include <stdlib.h> 16.Ft void * 17.Fn bsearch "const void *key" "const void *base" "size_t nmemb" "size_t size" "int (*compar) (const void *, const void *)" 18.Sh DESCRIPTION 19The 20.Fn bsearch 21function searches an array of 22.Fa nmemb 23objects, the inital member of which is 24pointed to by 25.Fa base , 26for a member that matches the object pointed to by 27.Fa key . 28The size of each member of the array is specified by 29.Fa size . 30.Pp 31The contents of the array should be in ascending sorted order according 32to the comparison function referenced by 33.Fa compar . 34The 35.Fa compar 36routine 37is expected to have two 38two arguments which point to the 39.Fa key 40object and to an array member, in that order, and should return an integer 41less than, equal to, or greater than zero if the 42.Fa key 43object is found, respectively, to be less than, to match, or be 44greater than the array member. 45.Sh RETURN VALUES 46The 47.Fn bsearch 48function returns a pointer to a matching member of the array, or a null 49pointer if no match is found. 50If two members compare as equal, which member is matched is unspecified. 51.Sh SEE ALSO 52.Xr db 3 , 53.Xr lsearch 3 , 54.Xr qsort 3 , 55.\" .Xr tsearch 3 56.Sh STANDARDS 57The 58.Fn bsearch 59function conforms to 60.St -ansiC . 61