IniParser+win7解析配置文件INI

最近做实验用到了ini配置文件,读取过程高端到我不太敢相信做实验的人自己会写一个用键值对来存取文件的库,后来一查原来Iniparser是一个比较通用的读取ini配置文件的库,看起来我还是知道的太少了.... IniParser+win7解析配置文件INI
首先,可以直接在网上下载IniParser的源文件 http://ndevilla.free.fr/iniparser, 编译的时候如果是Linux的话就直接make,如果windows只要把文件中对于#include 的引用注释即可直接使用。可以看到库非常简短,但是实现的功能真的是让我们这些天天在配置问题和中间文件格式中苦苦挣扎的图像狗感动到流泪啊~
【IniParser】
IniParser is a simple C library offering ini file parsing services. The library is pretty small (less than 1500 lines of C) and robust, and does not depend on any other external library to compile. It is written in ANSI C and should compile on most platforms without difficulty.
IniParser是一个解析ini文件的C函数库,它小而稳定,并且平台无关,用ANSI C编写。
【IniFile】
An ini file is an ASCII file describing simple parameters (character strings, integers, floating-point values or booleans) in an explicit format, easy to use and modify for users.
Ini文件是一个有特定格式和简单参数   (character strings, integers, floating-point values or booleans) 的ASCII文件,非常易于用户创建和修改。
【Ini File Format】
1.Ini文件通过Sections来分段,通过以下的格式来定义:
[Section Name]
i.e. the section name enclosed in square brackets, alone on a line. Sections names are allowed to contain any character but square brackets or linefeeds.(注意章节方括号自占一行并且里面的字符不能有方括号或者换行)
2.  Ini文件的Section内部,变量通过如下的方式申明:
Key = value :comment;
其中,key可以是任意字符串(可以包含空格),value在等号右边,其可以包含任意字符,它也可以通过双引号包含给出, 如果,如果当前value没有被双引号包含,那么解析出的value会包含从等号右边第一个到comment之前的最后一个字符。
Hello = "this is a long string value" ; comment 
Hello = this is a long string value ; comment
Ps: 行尾的comment和分号是可选的,如果有comment,那么它就会从第一个符号到分号后的尽头来识别
3. 多行文本通过反斜杠来连接
Multiple = Line 1 \ 
 Line 2 \
  Line 3 \
  Line 4 ; comment
【Using IniParser】
使用时只要include"iniparser.h"即可。在识别的时候,comments会被解析器丢弃,section的内容被识 别,比如说下面的seciton:
[Section] Keyword = value ; comment
 会被转换为如下的键值对:
("section:keyword", "value")

功能

int 

iniparser_getnsecdictionary* D

 

在字典中的部分路段,获取数。 

void 

iniparser_getsecnamedictionary* Dint n

 

得到N节在字典的名称。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值