- 论坛徽章:
- 0
|
工程:跨平台INI文件读写API(C版本)
版本: 0.2.0
授权方式:GNU GPL
著作权所有(c) 2007 Midapex
本程序为自由软件;您可依据自由软件基金会所发表的GNU通用公共授权条款规定,就本程序再为发布与/或修改;无论您依据的是本授权的第二版或(您自行选择的)任一日后发行的版本。
本程序是基于使用目的而加以发布,然而不负任何担保责任;亦无对适售性或特定目的适用性所为的默示性担保。详情请参照GNU通用公共授权。
源代码下载地址:
http://www.cppblog.com/Files/dyj057/inifile0.2.0.zip
或在这里下载:
![]()
文件:
inifile0.2.0.zip
大小:
3KB
下载:
下载
描述:
版本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.实现小巧精致,长期开源支持。
使用示例代码如下:
1 /**
2 * @file
3 * @brief test ini file api
4 * @author Deng Yangjun
5 * @date 2007-1-9
6 * @version 0.2
7 */
8 #include
9 #include "inifile.h"
10
11 #define BUF_SIZE 256
12
13 int main()
14 {
15 const char *file ="myconfig.ini";
16 const char *section = "student";
17 const char *name_key = "name";
18 const char *age_key = "age";
19 char name[BUF_SIZE]={0};
20 int age;
21
22 //write name key value pair
23 if(!write_profile_string(section,name_key,"Tony",file))
24 {
25 printf("write name pair to ini file fail\n");
26 return -1;
27 }
28
29 //write age key value pair
30 if(!write_profile_string(section,age_key,"20",file))
31 {
32 printf("write age pair to ini file fail\n");
33 return -1;
34 }
35
36 printf("[%s]\n",section);
37 //read string pair, test read string value
38 if(!read_profile_string(section, name_key, name, BUF_SIZE,"",file))
39 {
40 printf("read ini file fail\n");
41 return -1;
42 }
43 else
44 {
45 printf("%s=%s\n",name_key,name);
46 }
47
48 //read age pair, test read int value.
49 //if read fail, return default value
50 age = read_profile_int(section,age_key,0,file);
51 printf("%s=%d\n",age_key,age);
52
53 return 0;
54 }
55
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/86665/showart_1880712.html |
|