首页 > 解决方案 > C & libconfig: config_lookup_bool 返回 CONFIG_FALSE

问题描述

我正在尝试从一组中读取布尔设置。我正在使用以下代码,但config_lookup_bool总是返回 CONFIG_FALSE。据我了解,它应该将值写入send_keys并返回 CONFIG_TRUE 。

代码:

int send_keys;
config_t cfg;

config_init(&cfg);
config_read_file(&cfg, "config.cfg")

if (config_lookup_bool(&cfg, "settings.send_keys", &send_keys))
{
    // do something here
}

配置文件:

settings :
{
  send_keys = "true";
  start_apps = "false";
  sync_clocks = "false";
  pc_clock_is_origin = "true";
  calibration_start_time = 0L;
};

我的代码或我的想法有什么错误吗?

标签: clibconfig

解决方案


感谢您的输入。问题是我在“”中有真/假,因此它被解析为字符串。应该是

settings :
{
  send_keys = true;
  start_apps = false;
  sync_clocks = false;
  pc_clock_is_origin = true;
  calibration_start_time = 0L;
};

推荐阅读