I've an issue:
name = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Store inventory:
params =
{
myparams= ( { max_len = 1024UL;
author = "Robert Louis Stevenson";
price = 29.99;
qty = 5; }
);
};
Do you know how to retrivie from the main this value 1024UL? It's not an integer, but a particular int (unsigned long). I've not found a function to do that. You can see the function config_setting_lookup_int, but obviously it doesn't work becaus the value to retrieve is not an int (1024UL). Thank you everybody for your help!
config_t cfg;
config_setting_t *setting;
const char *str;
config_init(&cfg);
/* Read the file. If there is an error, report it and exit. */
if(! config_read_file(&cfg, "file.cfg"))
{
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
return(EXIT_FAILURE);
}else{
printf("Config file is OK\n");
}
/* Get the store name. */
if(config_lookup_string(&cfg, "name", &str))
printf("Store name: %s\n\n", str);
else
fprintf(stderr, "No 'name' setting in configuration file.\n");
setting = config_lookup(&cfg, "params.myparams");
if(setting != NULL)
{
int count = config_setting_length(setting);
int i;
printf("%-30s %-30s %-6s %s\n", "TITLE", "AUTHOR", "PRICE", "QTY");
for(i = 0; i < count; ++i)
{
config_setting_t *book = config_setting_get_elem(setting, i);
/* Only output the record if all of the expected fields are present. */
const char *author;
int max_len;
double price;
int qty;
if(!(config_setting_lookup_int(book, "max_len", &max_len)
&& config_setting_lookup_string(book, "author", &author)
&& config_setting_lookup_float(book, "price", &price)
&& config_setting_lookup_int(book, "qty", &qty)))
continue;
printf("%-30d %-30s $%6.2f %3d\n", max_len, author, price, qty);
}
putchar('\n');
}