lsearch.3c (2010 09)

l
lsearch(3C) lsearch(3C)
#include <stdio.h>
#define TABSIZE 50
#define ELSIZE 120
char line[ELSIZE], tab[TABSIZE][ELSIZE], *lsearch( );
size_t nel = 0;
int strcmp( );
...
while (fgets(line, ELSIZE, stdin) != NULL &&
nel < TABSIZE)
(void) lsearch(line, (char *)tab, &nel,
ELSIZE, strcmp);
...
RETURN VALUE
If the searched-for datum is found, both
lsearch()
and lfind() return a pointer to it. Otherwise,
lfind() returns NULL and lsearch() returns a pointer to the newly added element.
WARNINGS
Undefined results can occur if there is not enough room in the table to add a new item.
SEE ALSO
bsearch(3C), hsearch(3C), tsearch(3C), thread_safety(5).
STANDARDS CONFORMANCE
lsearch(): AES, SVID2, SVID3, XPG2, XPG3, XPG4
lfind(): AES, SVID2, SVID3, XPG2, XPG3, XPG4
2 Hewlett-Packard Company 2 HP-UX 11i Version 3: September 2010