Back to index

glibc  2.9
tst-hsearch.c
Go to the documentation of this file.
00001 #include <search.h>
00002 #include <stdio.h>
00003 
00004 int
00005 main (void)
00006 {
00007   int a = 1;
00008   int b = 2;
00009   ENTRY i;
00010   ENTRY *e;
00011 
00012   if (hcreate (20) == 0)
00013     {
00014       puts ("hcreate failed");
00015       return 1;
00016     }
00017 
00018   i.key = (char *) "one";
00019   i.data = &a;
00020   if (hsearch (i, ENTER) == NULL)
00021     return 1;
00022 
00023   i.key = (char *) "one";
00024   i.data = &b;
00025   e = hsearch (i, ENTER);
00026   printf ("e.data = %d\n", *(int *) e->data);
00027   if (*(int *) e->data != 1)
00028     return 1;
00029 
00030   return 0;
00031 }