我想使用简单的C程序来读取一个简单的YAML文件。我认为最好的方法是使用以下库:Pyyaml.org。使用C脚本读取YAML文件
阅读维基页面后,我试着在这里使用了一些例子: http://pyyaml.org/browser/libyaml/branches/stable/tests/ 但像我这样的小白,这不是很简单的理解。
举例来说,如果我得到这个更加简单YAML文件(名为test.yml):
test:
- {conf: hi}
- {conf: test}
- {conf: abc}
我该怎么做才能做到somethig这样的:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
/* I do not really see how to load the file here... */
char *conf[3] = {"hi", "test", "abc"}; /* configuration of the YAML file */
int i;
for (i = 0; i < 3; i++)
{
printf("content: %s\n", conf[i]);
}
return 0;
}
...但从给定的YAML文件?
非常感谢您的任何建议!
“script”这个词的定义不是很明确,但我认为大多数人会同意C不是一种脚本语言:) – Thomas 2009-11-10 16:28:35
另外,PyYAML是一个Python库。祝你好运使用它从C. – Thomas 2009-11-10 16:30:10
我想他意味着他想要使用libYAML库,这是链接的测试是什么(以及PyYAML基于什么) – 2009-11-10 16:49:33