1LSEARCH(3)                 Linux Programmer's Manual                LSEARCH(3)
2
3
4

NAME

6       lfind, lsearch - linear search of an array
7

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

CONFORMING TO

36       SVr4, 4.3BSD, POSIX.1-2001.  Present in libc since libc-4.6.27.
37

BUGS

39       The naming is unfortunate.
40

SEE ALSO

42       bsearch(3), hsearch(3), tsearch(3)
43

COLOPHON

45       This  page  is  part of release 3.22 of the Linux man-pages project.  A
46       description of the project, and information about reporting  bugs,  can
47       be found at http://www.kernel.org/doc/man-pages/.
48
49
50
51GNU                               1999-09-27                        LSEARCH(3)
Impressum