有没有一种优雅的方式来解析 ac 程序中的 .conf 文件?说,如果我有普通的文本文件-
param1 = 22
param2 = 99
param34 = 11
param11 = 15
...
在一个函数调用中获得访问权限会很好,比如:
int c = xfunction(my.conf, param34);
现在 c = 11。非常感谢提前。
有没有一种优雅的方式来解析 ac 程序中的 .conf 文件?说,如果我有普通的文本文件-
param1 = 22
param2 = 99
param34 = 11
param11 = 15
...
在一个函数调用中获得访问权限会很好,比如:
int c = xfunction(my.conf, param34);
现在 c = 11。非常感谢提前。
#include <stdio.h>
#include <stdlib.h>
#define xfunction(file, param) \
system("awk '/^" #param " = [0-9]+$/{ num = $3 };END { exit num }' " #file)
int main(void){
int c = xfunction(my.conf, param34);
printf("%d\n", c);
return 0;
}
最好使用如下的链表
struct node
{
char *key;
int value;
};
并将所有key
value
对分配给节点,您可以node
在将 conf 文件解析到linked list
.
稍后当您搜索时,您可以简单地遍历并通过简单的方式linked list
检查并获取值。key
strcmp()