HP-UX Reference (11i v1 00/12) - 3 Library Functions A-M (vol 6)

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man3/!!!intro.3c
________________________________________________________________
___ ___
h
hsearch(3C) hsearch(3C)
/* put info in structure, and structure in item */
item.key = str_ptr;
item.data = (char *)info_ptr;
str_ptr += strlen(str_ptr) + 1;
info_ptr++;
/* put item into table */
(void) hsearch(item, ENTER);
}
/* access table */
item.key = name_to_find;
while (scanf("%s", item.key) != EOF) {
if ((found_item = hsearch(item, FIND)) != NULL) {
/* if item is in the table */
(void)printf("found %s, age = %d, room = %d\n",
found_item->key,
((struct info *)found_item->data)->age,
((struct info *)found_item->data)->room);
} else {
(void)printf("no such employee %s\n",
name_to_find);
}
}
}
APPLICATION USAGE
hcreate(), hdestroy() and hsearch() are thread-safe. These interfaces are not async-cancel-safe.
RETURN VALUE
hsearch() returns a NULL pointer if either the action is FIND and the item could not be found or the
action is ENTER and the table is full.
hcreate() returns zero if it cannot allocate sufficient space for the table.
WARNINGS
hsearch() and hcreate() use malloc() to allocate space (see malloc(3C)).
Only one hash search table can be active at any given time.
SEE ALSO
bsearch(3C), lsearch(3C), malloc(3C), string(3C), tsearch(3C).
STANDARDS CONFORMANCE
hsearch(): AES, SVID2, SVID3, XPG2, XPG3, XPG4
hcreate(): AES, SVID2, SVID3, XPG2, XPG3, XPG4
hdestroy(): AES, SVID2, SVID3, XPG2, XPG3, XPG4
HP-UX Release 11i: December 2000 2 Section 3433
___
___