Chinaunix首页 | 论坛 | 博客
  • 博客访问: 303701
  • 博文数量: 60
  • 博客积分: 2579
  • 博客等级: 大尉
  • 技术积分: 570
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-17 14:54
文章分类

全部博文(60)

文章存档

2011年(1)

2010年(1)

2009年(35)

2008年(23)

分类: C/C++

2009-11-09 13:43:01

最近要解析ini文件,不想自己写,上网找了一下,还真了一个比较小巧开源的动态库,不过该文件有点儿小bug,但是作者似乎不再维护了,我就自己修改了一点儿bug,更新上来给要用的兄弟们共享。
文件: inifile.zip
大小: 2KB
下载: 下载
 
 
    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 

阅读(2977) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~