Git init
[pkgs/e/elektra.git] / examples / binary.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include <kdb.h>
6 #include <stdio.h>
7
8 /*
9  * Save this program as binary.c
10  * Compile and run it as bellow.
11  *
12  * Change the data type of 'i' from int to char, and to float,
13  * and to double, and recompile it.
14  *
15  * You should not use binary types.
16  * Consider a text representation of
17  * your types and write them as string.
18  *
19  * cc -L/lib -lkdb binary.c -o binary; ./binary; cat user/tmp/bin
20  *
21  */
22
23 int main(void)
24 {
25         int i=25;
26         Key *key=keyNew("user/examples/bin",KEY_END);
27         Key *back;
28         KDB * handle= kdbOpen();
29
30         keySetBinary(key,&i,sizeof(i));
31         kdbSetKey(handle,key);
32         keyDel(key);
33
34         back=keyNew("user/examples/bin", KEY_END);
35         kdbGetKey(handle,back);
36         printf("Got back: %d\n",*(int*)keyValue(back));
37         keyRemove(back);
38         kdbSetKey(handle,key);
39         keyDel(back);
40
41         kdbClose(handle);
42         return 0;
43 }