分类: C/C++
2009-11-09 13:43:01
|
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