如何读取 value值呢?
有个txt文件 内容如下:
homepage=http://192.168.45.104/TestAPI/
homepage=http://192.168.29.40/TestAPI
a=22
b=22
test-frequency=7380000
screen-width=1280
a=7
b=2
写一个方法 给地key值,取出相应的 value 若value相同 就取第一个
[解决办法]
//有个kv.txt文件 内容如下://homepage=http://192.168.45.104/TestAPI/////homepage=http://192.168.29.40/TestAPI//////a=22////b=22//////test-frequency=7380000//////screen-width=1280////a=7//b=2////////写一个方法 给地key值,取出相应的 value 若value相同 就取第一个#include <stdio.h>char *getvalue(char *key) { FILE *f; char ln[80],k[40]; static char v[40]; v[0]=0; f=fopen("kv.txt","r"); if (NULL==f) return v; sprintf(k,"%.30s=%%39[^\n]",key); while (1) { if (NULL==fgets(ln,80,f)) break; if (1==sscanf(ln,k,v)) break; } fclose(f); return v;}void main() { printf("getvalue(homepage)" "==%s\n",getvalue("homepage") ); printf("getvalue(a)" "==%s\n",getvalue("a") ); printf("getvalue(screen-width)" "==%s\n",getvalue("screen-width")); printf("getvalue(haha)" "==%s\n",getvalue("haha") );}//getvalue(homepage)==http://192.168.45.104/TestAPI///getvalue(a)==22//getvalue(screen-width)==1280//getvalue(haha)==