有时我们自己写Linux下配置文件,需要手动解析,然后使得程序可以配置的 类似于以下格式 simple.conf:
## Sample configuration file
ip=192.16.31.2 port=22 Desktop-Picture = /usr/images/earth.jpg Position = Centered
直接上代码解析:
头文件ccl.h
#ifndef CLL_KVCONF_H
#define CLL_KVCONF_H
#define KEYVALLEN 256
/* 删除左边的空格 */
char * l_trim(char * szOutput, const char *szInput);
/* 删除右边的空格 */
char *r_trim(char *szOutput, const char *szInput);
/* 删除两边的空格 */
char * a_trim(char * szOutput, const char * szInput);
int GetProfileString(char *profile, char *AppName, char *KeyName, char *KeyVal );
#endif //CLL_KVCONF_H
源文件ccl.cpp
#include <