-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.c
43 lines (34 loc) · 929 Bytes
/
example.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include "trie.h"
/* some values, we want to attach to every
word in the trie data base. */
enum type_of_word {
type_a, type_b
};
int main (int argc, char *argv[])
{
int ret = EXIT_SUCCESS;
ssize_t res;
struct trie * dict = trie_new ();
if (argc <= 1)
{
(void) fprintf (stderr, "usage: %s word to find\n", argv[0]);
ret = EXIT_FAILURE;
goto out;
}
trie_add_word (dict, "hello", strlen ("hello"), (ssize_t)type_a);
trie_add_word (dict, "hell", strlen ("hell"), (ssize_t)type_b);
printf ("Printing the trie.\n");
trie_print (dict);
res = trie_search (dict, argv[1], strlen (argv[1]));
printf ("searching '%s' in the database -- %s\n",
argv[1], res != TRIE_NOT_LAST
? (enum type_of_word)res == type_a ? "yes, type A" : "yes, type B"
: "no");
out:
trie_free (dict);
return ret;
}