lsearch()

perform linear search of table 

Function


SYNOPSIS

#include <search.h>

void * lsearch(const void *key, void *base, size_t *nelp, size_t width, int (*compar)(const void *, const void *));


DESCRIPTION

The lsearch() function performs a linear search of a table. This function returns a pointer into a table indicating where a specified key is located in the table. If key is not found in the table, it adds key to the end of the table. Free space must be available at the end of the table.

All comparisons are done with a user-supplied routine, compar. This routine is called with two arguments, the pointers to the elements being compared. It returns an integer less than, equal to, or greater than 0, according to whether the first argument is to be considered less than, equal to, or greater than the second argument. The comparison function need not compare every byte, so arbitrary data may be contained in the elements in addition to the values being compared.


PARAMETERS

key 

Points to an entry containing the key that specifies the entry to find in the table.

base 

Points to the first entry in the table to be searched.

nelp 

Points to an integer that specifies the current number of entries in the table to be searched. This integer is incremented whenever an entry is added to the table.

width 

Specifies the size of each entry, in bytes.

compar 

Is the comparator function.


RETURN VALUES

If an entry in the table matches the key, lsearch() function returns a pointer to the entry's location in the table. Otherwise, the function returns a pointer to the location of the newly added table entry.


CONFORMANCE

UNIX 98.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
bsearch(), hsearch(), lfind(), qsort(), tsearch()


PTC MKS Toolkit 10.3 Documentation Build 39.