2
我尝试使用libconfig安装c程序。有example1.c:指针使用.cfg文件的警告
int main()
{
const char **channel;
config_t config;
config_init(&config);
config_read_file(&config, "example.cfg");
if(config_lookup_string(&config,"value.channel",&channel) == CONFIG_FALSE)
{
printf("Failed to read fields\n");
return 1;
}
printf("argumente = %s\n", (char *)channel);
return 0;
}
和example.cfg文件
值= {信道= “你好”; }
如果我编译它
GCC example1.c -lconfig
它说:
example1.c:39:3: Warning: delivery of arguments 3 from »config_lookup_string« of a incompatible pointer
/usr/include/libconfig.h:244:26: Detailed: »const char **« expected, but argument has typ »const char ***«
有趣的是,它的工作原理...输出是: argumente = hello
我该如何摆脱此警告?
如果我改变decleration到const char *channel
和输出printf("argumente = %s\n", channel);
,我收到在启动段错误,在编译像一个警告... Detailed: »const char **« expected, but argument has typ »const char *«
改为const char * channel;并在最后printf(“argumente =%s \ n”,频道);但是我在开始时仍然会遇到Segfault ... – Fendrix
@Fendrix,您必须更改其他内容 - 根据最初的示例,您无法获得该错误消息。怎么会期待一次'char *'和另一个'char **'? –