我有一个问题:
name = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Store inventory:
params =
{
myparams= ( { max_len = 1024UL;
author = "Robert Louis Stevenson";
price = 29.99;
qty = 5; }
);
};
你知道如何从主这个值 1024UL 中检索吗?它不是整数,而是特定的 int(无符号长整数)。我还没有找到这样做的功能。您可以看到函数 config_setting_lookup_int,但显然它不起作用,因为要检索的值不是 int (1024UL)。谢谢大家的帮助!
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');
}