lfind
raw OCR
Performs a Unear search.
Defined in header <stdlib.h>
Syntax
#include <stdlib.h>
void *lfind(const void *keif, const void *base,size_t *num, size_t width,
int i*fcmp){const void *, const void *));
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ |
Remarks
Ifind makes a linear search for the value of key in an array of sequential records. It uses a user-defined comparison routine (fcmp).
The array is described as having *num records that are width bytes wide, and begins at the memory location pointed to by base.
Return value
Ifind returns the address of the first entry in the table that matches the search key. If no match is found, Ifind returns null. The comparison routine must return 0 if *eleml == *elem2, and nonzero otherwise (eleml and eleml are its two parameters).
See also
Example
#include <stdio.h>
#include <stdlib.h>
int compare (int *x, int *y)
{
return( *x - *y );
int main(void)
{
int array[5] = {35, 87, 46, 99, 12};
size_t nelem = 5;
int key =99;
int *result;
result = (int *) lfind(&key, array, &nelem,
sizeof (int),
(int(*)(const void *,const void *))compare);
if (result)
printf("Number %d found\n",key);
else
printf("Number %d not found\n",key);
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Extraction notes
- heading `Ifind` read as `lfind`
Stable link: /3.1/stdlib.h/lfind/
· short form /3.1/lfind/