1LSEARCH(3) Linux Programmer's Manual LSEARCH(3)
2
3
4
6 lfind, lsearch - linear search of an array
7
9 #include <search.h>
10
11 void *lfind(const void *key, const void *base, size_t *nmemb,
12 size_t size, int(*compar)(const void *, const void *));
13
14 void *lsearch(const void *key, void *base, size_t *nmemb,
15 size_t size, int(*compar)(const void *, const void *));
16
18 lfind() and lsearch() perform a linear search for key in the array base
19 which has *nmemb elements of size bytes each. The comparison function
20 referenced by compar is expected to have two arguments which point to
21 the key object and to an array member, in that order, and which returns
22 zero if the key object matches the array member, and non-zero other‐
23 wise.
24
25 If lsearch() does not find a matching element, then the key object is
26 inserted at the end of the table, and *nmemb is incremented. In par‐
27 ticular, one should know that a matching element exists, or that more
28 room is available.
29
31 lfind() returns a pointer to a matching member of the array, or NULL if
32 no match is found. lsearch() returns a pointer to a matching member of
33 the array, or to the newly added member if no match is found.
34
36 SVr4, 4.3BSD, POSIX.1-2001. Present in libc since libc-4.6.27.
37
39 The naming is unfortunate.
40
42 bsearch(3), hsearch(3), tsearch(3)
43
44
45
46GNU 1999-09-27 LSEARCH(3)