aboutsummaryrefslogtreecommitdiffstats
path: root/samples/c/sample2.c
blob: 09c45de39b08fc7de02c210610b51f8631ebf0c9 (plain)
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
44
45
46
47
48
49
50
51
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;
}


/***************************************************************************/