我想使用簡單的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