"Fossies" - the Fresh Open Source Software Archive 
Member "deheader-1.10/test/bsort.c" (30 Jan 2023, 1161 Bytes) of package /linux/privat/deheader-1.10.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*
2 * Items: bsort(
3 * Standardized-By: SuS
4 * Not-Detected-by: gcc-4.4.3 + Linux
5 */
6
7 /* example taken pretty much directly from SuS */
8
9 #ifndef __DEHEADER__
10 #include <stdio.h>
11 #include <string.h>
12 #endif
13 #include <stdlib.h>
14
15 #define TABSIZE 1000
16
17 struct node { /* these are stored in the table */
18 char *string;
19 int length;
20 };
21 struct node table[TABSIZE]; /* table to be searched */
22
23 int
24 node_compare(const void *node1, const void *node2)
25 {
26 return strcoll(((const struct node *)node1)->string,
27 ((const struct node *)node2)->string);
28 }
29
30 main(int argc, char **argv)
31 {
32 struct node *node_ptr, node;
33 char str_space[20]; /* space to read string into */
34
35 node.string = str_space;
36 while (scanf("%s", node.string) != EOF) {
37 node_ptr = (struct node *)bsearch((void *)(&node),
38 (void *)table, TABSIZE,
39 sizeof(struct node), node_compare);
40 if (node_ptr != NULL) {
41 (void)printf("string = %20s, length = %d\n",
42 node_ptr->string, node_ptr->length);
43 } else {
44 (void)printf("not found: %s\n", node.string);
45 }
46 }
47 }
48
49