]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - man3/hsearch.3
ffix
[thirdparty/man-pages.git] / man3 / hsearch.3
index e978bcbbfa8cda8a242342c0df01e8adfd7ebedd..8668e75c1cf4a0789be576685d2acc34ab6b8ec9 100644 (file)
@@ -39,7 +39,7 @@ hcreate, hdestroy, hsearch \- hash table management
 .BI "ENTRY *hsearch(ENTRY " item ", ACTION " action );
 .sp
 .B "void hdestroy(void);"
-.sp 2
+.sp
 .B #define _GNU_SOURCE
 .br
 .B #include <search.h>
@@ -150,47 +150,45 @@ The following program inserts 24 items in to a hash table, then prints
 some of them.
 .nf
 
-    #include <stdio.h>
-    #include <stdlib.h>
-    #include <search.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <search.h>
     
-    char *data[] = { "alpha", "bravo", "charlie", "delta",
-         "echo", "foxtrot", "golf", "hotel", "india", "juliet",
-         "kilo", "lima", "mike", "november", "oscar", "papa",
-         "quebec", "romeo", "sierra", "tango", "uniform",
-         "victor", "whisky", "x-ray", "yankee", "zulu" 
-    };
+char *data[] = { "alpha", "bravo", "charlie", "delta",
+     "echo", "foxtrot", "golf", "hotel", "india", "juliet",
+     "kilo", "lima", "mike", "november", "oscar", "papa",
+     "quebec", "romeo", "sierra", "tango", "uniform",
+     "victor", "whisky", "x-ray", "yankee", "zulu" 
+};
 
-    int main() {
-      ENTRY e, *ep;
-      int i;
+int main() {
+    ENTRY e, *ep;
+    int i;
     
-      /* starting with small table, and letting it grow does not work */
-      hcreate(30);
-      for (i = 0; i < 24; i++) {
-          e.key = data[i]; 
-          /* data is just an integer, instead of a
-             pointer to something */
-          e.data = (void *)i;
-          ep = hsearch(e, ENTER);
-          /* there should be no failures */
-          if (ep == NULL) {
+    /* starting with small table, and letting it grow does not work */
+    hcreate(30);
+    for (i = 0; i < 24; i++) {
+        e.key = data[i]; 
+        /* data is just an integer, instead of a 
+           pointer to something */
+        e.data = (void *)i;
+        ep = hsearch(e, ENTER);
+        /* there should be no failures */
+        if (ep == NULL) {
             fprintf(stderr, "entry failed\\n");
             exit(1);
-          }
-      }
-      for (i = 22; i < 26; i++) {
-          /* print two entries from the table, and
-             show that two are not in the table */
-          e.key = data[i];
-          ep = hsearch(e, FIND);
-          printf("%9.9s \-> %9.9s:%d\\n", e.key,
-                 ep ? ep\->key : "NULL",
-                 ep ? (int)(ep->data) : 0);
-      }
-      return 0;
+        }
     }
-
+    for (i = 22; i < 26; i++) {
+        /* print two entries from the table, and
+           show that two are not in the table */
+        e.key = data[i];
+        ep = hsearch(e, FIND);
+        printf("%9.9s \-> %9.9s:%d\\n", e.key,
+               ep ? ep\->key : "NULL", ep ? (int)(ep->data) : 0);
+    }
+    return 0;
+}
 .fi
 .SH "SEE ALSO"
 .BR bsearch (3),