HP C/iX Library Reference Manual (30026-90004)

Chapter 5 231
HP C/iX Library Function Descriptions
lfind
lfind
Performs a linear search.
Syntax
#include <stdio.h>
char *lfind ((char *)
key
, (char *)
base
,
nelp
, sizeof(*
key
),
compar
)
unsigned *
nelp
int (*
compar
)();
Parameters
key
A pointer to the value to be found in the table.
base
A pointer to the first element in the table.
nelp
A pointer to an integer containing the current number of elements in the
table.
width
The size of each datum in the table; it is the width of each table row.
compar
A pointer to a comparison function that you must supply, such as strcmp.
It is called with two arguments that point to the elements being compared.
The function must return zero if the elements are equal, and non-zero if
they are not equal.
Return Values
x A character pointer to the table entry being sought.
NULL The searched item is not found.
Description
This function is a linear search function generalized from Knuth Algorithm S (6.1).
1
It
returns a pointer into a table indicating where an item may be found.
This function is the same as lsearch except that if the item is not found, it is not added to
the table. Instead, a null pointer is returned.
The pointers to the key and the element at the base of the table should be of type
pointer-to-element and should be cast to type pointer-to-character.
The comparison function does not need to compare every byte, so arbitrary data may be
contained in the elements in addition to the values being compared.
The value returned is declared as type pointer-to-character, but should be cast as type
pointer-to-element.
1. The Art of Computer Programming, Vol.3 (Sorting and Searching) by Donald Ervin Knuth (Reading,
Mass:Addison-Wesley, 1973).