.ini 文件格式如下:
[section1]
key1=value
...
keyn=value
[section2]
key1=value
...
keyn=value
代码如下:
#define _PARAM_GLOBALS_ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "userlib.h" #include "paramConfig.h"
#define SECTION_MAX_LEN 256
#define STRVALUE_MAX_LEN 256
#define LINE_CONTENT_MAX_LEN 256 //read value from .ini void IniReadValue(char* section, char* key, char* val, const char* file) { FILE* fp; int i = 0; int lineContentLen = 0; int position = 0; char lineContent[LINE_CONTENT_MAX_LEN]; bool bFoundSection = false; bool bFoundKey = false; fp = fopen(file, "r"); if(fp == NULL) { printf("%s: Opent file %s failed. ", __FILE__, file); return; } while(feof(fp) == 0) { memset(lineContent, 0, LINE_CONTENT_MAX_LEN); fgets(lineContent, LINE_CONTENT_MAX_LEN, fp); if((lineContent[0] == ';') || (lineContent[0] == '