|
|
HP-UX Reference > Llsearch(3C)HP-UX 11i Version 2: December 2007 Update |
|
NAMElsearch(), lfind() — linear search and update SYNOPSIS#include <search.h> void *lsearch( const void *key, void *base, size_t *nelp, size_t width, int (*compar)(const void *, const void *) ); void *lfind( const void *key, const void *base, size_t *nelp, size_t width, int (*compar)(const void *, const void *) ); DESCRIPTION
NotesThe pointers to the key and the element at the base of the table should be of type pointer-to-element, and cast to type pointer-to-character. The comparison function need not compare every byte, so arbitrary data may be contained in the elements in addition to the values being compared. Although declared as type pointer-to-character, the value returned should be cast into type pointer-to-element. EXAMPLESThis code fragment reads in ≤ TABSIZE strings of length ≤ ELSIZE and stores them in a table, eliminating duplicates. #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); ... |
|