工程:跨平台INI文件读写API(C版本)
版本: 0.2.0
授权方式:GNU GPL
著作权所有(c) 2007 Midapex
本程序为自由软件;您可依据自由软件基金会所发表的GNU通用公共授权条款规定,就本程序再为发布与/或修改;无论您依据的是本授权的第二版或(您自行选择的)任一日后发行的版本。
本程序是基于使用目的而加以发布,然而不负任何担保责任;亦无对适售性或特定目的适用性所为的默示性担保。详情请参照GNU通用公共授权。
源代码下载地址:http://www.cppblog.com/Files/dyj057/inifile0.2.0.zip
描述:
版本0.1.0发布以来,没想到这么受大家关注,也提出一些问题。我把问题整理了一下,重写了部分程序,然后发布为0.2.0版本,欢迎大家使用。
旧版本地址:http://www.cppblog.com/dyj057/archive/2006/01/24/3012.html
已测试通过的开发环境:
WinXP、Vista + VC6.0、VS2003、VS2005、VS2008
FC6.0、FC7.0、Ubuntu7.10 + GCC4.1
ARM-Linux+arm-linux-gcc3.3.2
项目特点:
1.使用标准C库函数,支持Windows、Linux、Unix等多平台。
2.实现小巧精致,长期开源支持。
使用示例代码如下:
/**
* @file
* @brief test ini file api
* @author Deng Yangjun
* @date 2007-1-9
* @version 0.2
*/
#include <stdio.h>
#include "inifile.h"
#define BUF_SIZE 256
int main()
{
const char *file ="myconfig.ini";
const char *section = "student";
const char *name_key = "name";
const char *age_key = "age";
char name[BUF_SIZE]={0};
int age;
//write name key value pair
if(!write_profile_string(section,name_key,"Tony",file))
{
printf("write name pair to ini file fail\n");
return -1;
}
//write age key value pair
if(!write_profile_string(section,age_key,"20",file))
{
printf("write age pair to ini file fail\n");
return -1;
}
printf("[%s]\n",section);
//read string pair, test read string value
if(!read_profile_string(section, name_key, name, BUF_SIZE,"",file))
{
printf("read ini file fail\n");
return -1;
}
else
{
printf("%s=%s\n",name_key,name);
}
//read age pair, test read int value.
//if read fail, return default value
age = read_profile_int(section,age_key,0,file);
printf("%s=%d\n",age_key,age);
return 0;
}