我想使用一个简单的 C 程序读取一个精简的 YAML 文件。我认为最好的方法是使用以下库:Pyyaml.org。
阅读wiki页面后,我尝试在这里使用一些示例:http: //pyyaml.org/browser/libyaml/branches/stable/tests/ 但是对于像我这样的菜鸟来说,理解起来并不是很简单。
例如,如果我得到这个更简单的 YAML 文件(名为test.yml):
test:
- {conf: hi}
- {conf: test}
- {conf: abc}
我该怎么做才能做这样的事情:
#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 文件?
非常感谢您的任何建议!