8 void create_example_ini_file(void);
9 int parse_ini_file(char * ini_name
);
11 int main(int argc
, char * argv
[])
16 create_example_ini_file();
17 status
= parse_ini_file("example.ini");
19 status
= parse_ini_file(argv
[1]);
24 void create_example_ini_file(void)
28 ini
= fopen("example.ini", "w");
31 # This is an example of ini file\n\
44 Grape = Cabernet Sauvignon ;\n\
57 int parse_ini_file(char * ini_name
)
61 /* Some temporary variables to hold query results */
67 ini
= iniparser_load(ini_name
);
69 fprintf(stderr
, "cannot parse file [%s]", ini_name
);
72 iniparser_dump(ini
, stderr
);
74 /* Get pizza attributes */
77 b
= iniparser_getboolean(ini
, "pizza:ham", -1);
78 printf("Ham: [%d]\n", b
);
79 b
= iniparser_getboolean(ini
, "pizza:mushrooms", -1);
80 printf("Mushrooms: [%d]\n", b
);
81 b
= iniparser_getboolean(ini
, "pizza:capres", -1);
82 printf("Capres: [%d]\n", b
);
83 b
= iniparser_getboolean(ini
, "pizza:cheese", -1);
84 printf("Cheese: [%d]\n", b
);
86 /* Get wine attributes */
88 s
= iniparser_getstr(ini
, "wine:grape");
90 printf("grape: [%s]\n", s
);
92 printf("grape: not found\n");
94 i
= iniparser_getint(ini
, "wine:year", -1);
96 printf("year: [%d]\n", i
);
98 printf("year: not found\n");
100 s
= iniparser_getstr(ini
, "wine:country");
102 printf("country: [%s]\n", s
);
104 printf("country: not found\n");
106 d
= iniparser_getdouble(ini
, "wine:alcohol", -1.0);
108 printf("alcohol: [%g]\n", d
);
110 printf("alcohol: not found\n");
113 iniparser_freedict(ini
);