diff options
author | Jonathan McCrohan <jmccrohan@gmail.com> | 2011-12-01 22:54:16 +0000 |
---|---|---|
committer | Jonathan McCrohan <jmccrohan@gmail.com> | 2011-12-01 22:54:16 +0000 |
commit | 58bf1382be0cbcf3f9649286fd2719b789a1595f (patch) | |
tree | b73665275a2d44879a8230c913b1ef21a42e57da /samples/c/sample2.c | |
download | libconfig-upstream/1.3.2.tar.gz |
Imported Upstream version 1.3.2upstream/1.3.2
Diffstat (limited to '')
-rw-r--r-- | samples/c/sample2.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/samples/c/sample2.c b/samples/c/sample2.c new file mode 100644 index 0000000..09c45de --- /dev/null +++ b/samples/c/sample2.c @@ -0,0 +1,52 @@ +/************************************************************************* + ** Sample2 + ** Load sample.cfg and access the "values" array + *************************************************************************/ + +#include <stdio.h> +#include <libconfig.h> + +struct config_t cfg; + +/***************************************************************************/ + +int main() +{ + /* Initialize the configuration */ + config_init(&cfg); + + /* Load the file */ + printf("loading [sample.cfg].."); + if (!config_read_file(&cfg, "sample.cfg")) + printf("failed\n"); + else + { + config_setting_t *array = NULL; + + printf("ok\n"); + + /* Display the "values" array */ + printf("display \"values\".."); + array = config_lookup(&cfg, "values"); + if (!array) + printf("failed\n"); + else + { + long value1,value2; + value1 = config_setting_get_int_elem(array, 0); + value2 = config_setting_get_int_elem(array, 1); + printf("[%lu %lu]..ok\n", value1, value2); + + printf("Done!\n"); + } + + } + + /* Free the configuration */ + config_destroy(&cfg); + + return 0; +} + + +/***************************************************************************/ |