Add to git.
[c2lib.git] / doc / eg_sash.c
1 #include <stdio.h>
2 #include <hash.h>
3 #include <pstring.h>
4
5 main ()
6 {
7   pool pool = global_pool;
8   sash h = new_sash (pool);
9   char *fruit;
10   const char *color;
11
12   sash_insert (h, "banana", "yellow");
13   sash_insert (h, "orange", "orange");
14   sash_insert (h, "apple", "red");
15   sash_insert (h, "kiwi", "green");
16   sash_insert (h, "grapefruit", "yellow");
17   sash_insert (h, "pear", "green");
18   sash_insert (h, "tomato", "red");
19   sash_insert (h, "tangerine", "orange");
20
21   for (;;)
22     {
23       printf ("Please type in the name of a fruit: ");
24       fruit = pgetline (pool, stdin, 0);
25
26       if (sash_get (h, fruit, color))
27         printf ("The color of that fruit is %s.\n", color);
28       else
29         printf ("Sorry, I don't know anything about that fruit.\n");
30     }
31 }