工程:跨平臺INI文件讀寫API(C版本)
版本: 0.2.0
授權(quán)方式:GNU GPL
著作權(quán)所有(c) 2007 Midapex
本程序為自由軟件;您可依據(jù)自由軟件基金會所發(fā)表的GNU通用公共授權(quán)條款規(guī)定,就本程序再為發(fā)布與/或修改;無論您依據(jù)的是本授權(quán)的第二版或(您自行選擇的)任一日后發(fā)行的版本。
本程序是基于使用目的而加以發(fā)布,然而不負任何擔保責任;亦無對適售性或特定目的適用性所為的默示性擔保。詳情請參照GNU通用公共授權(quán)。
源代碼下載地址:http://m.shnenglu.com/Files/dyj057/inifile0.2.0.zip
描述:
版本0.1.0發(fā)布以來,沒想到這么受大家關(guān)注,也提出一些問題。我把問題整理了一下,重寫了部分程序,然后發(fā)布為0.2.0版本,歡迎大家使用。
舊版本地址:http://m.shnenglu.com/dyj057/archive/2006/01/24/3012.html
已測試通過的開發(fā)環(huán)境:
WinXP、Vista + VC6.0、VS2003、VS2005、VS2008
FC6.0、FC7.0、Ubuntu7.10 + GCC4.1
ARM-Linux+arm-linux-gcc3.3.2
項目特點:
1.使用標準C庫函數(shù),支持Windows、Linux、Unix等多平臺。
2.實現(xiàn)小巧精致,長期開源支持。
使用示例代碼如下:
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 <stdio.h>
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