C语言读取配置文件
来源:互联网 发布:cms监控软件下载 编辑:程序博客网 时间:2024/05/17 03:40
1
2
3
# ip=sadf
ip =192.168.246.22
dns = 218.85.157.99
assert() 宏用法
注意:assert是宏,而不是函数。在C的assert.h头文件中。
assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义:
#include <assert.h>void assert( int expression );assert的作用是先计算表达式expression,如果其值为假(即为0),那么它先向标准错误流stderr打印一条出错信息,然后通过调用abort来终止程序运行;否则,assert()无任何作用。宏assert()一般用于确认程序的正常操作,其中表达式构造无错时才为真值。完成调试后,不必从源代码中删除assert()语句,因为宏NDEBUG有定义时,宏assert()的定义为空。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
/* 删除左边的空格 */
char * del_left_trim(char *str) {
assert(str != NULL);
for
(;*str !=
'\0'
&& isblank(*str) ; ++str);
return
str;
}
/* 删除两边的空格 */
char * del_both_trim(char * str) {
char *p;
char * szOutput;
szOutput = del_left_trim(str);
for
(p = szOutput + strlen(szOutput) - 1; p >= szOutput && isblank(*p);
--p);
*(++p) =
'\0'
;
return
szOutput;
}
/*主函数*/
int main(int argc, char **argv) {
FILE * fp = NULL;
/*打开配置文件a.txt*/
fp = fopen(
"./a.txt"
,
"r"
);
/*緩沖區*/
char buf[64];
char s[64];
/*分割符*/
char * delim =
"="
;
char * p;
char ch;
while
(!feof(fp)) {
if
((p = fgets(buf, sizeof(buf), fp)) != NULL) {
strcpy(s, p);
ch=del_left_trim(s)[0];
/*判断注释 空行,如果是就直接下次循环*/
if
(ch ==
'#'
|| isblank(ch) || ch==
'\n'
)
continue
;
/*分割字符串*/
p=strtok(s, delim);
if
(p)
printf
(
"%s"
, del_both_trim(p));
while
((p = strtok(NULL, delim)))
printf
(
"%s "
, del_both_trim(p));
printf
(
"\n"
);
}
}
return
0;
}
1
2
3
ip192.168.246.22
dns218.85.157.99
0 0
- C语言读取配置文件
- C语言读取配置文件
- C语言读取配置文件
- C语言读取配置文件
- C语言读取配置文件例子
- C语言读取配置文件代码
- 用C语言读取配置文件
- 【C/C++】C语言读取简单配置文件
- C语言读取类unix风格配置文件
- 网上找的c语言读取配置文件
- linux编程(C语言读取配置文件)
- C语言读取类unix风格配置文件
- C语言读取配置文件的另类写法
- C语言编写读取配置文件程序
- Linux C语言实现读取ini配置文件
- Linux下用C语言读取配置文件
- 用c语言实现读取配置文件源码
- C语言读取配置文件以及128字节对齐.bin配置文件
- C++学习笔记(二): 迭代器
- 研究生生活总结
- 1-9的九个数排列
- Duilib的异性窗体
- Android应用程序架构
- C语言读取配置文件
- 剑指offer 6.3 知识迁移能力6-和为s的连续正数序列
- 公钥和私钥
- Oakley Jawbone Matte Black Though
- Android Service 之三(Bind Service, 继承自 Binder 类)
- Oakley Frogskins Sunglasses Cheap "Falling glaciers may well be constructed from toxins and / or lun
- Oakley sunglasses UK Sale 5 cyber thursday web-sites to express by internet marketing
- Cheap Oakley Sunglasses Every different device on the web requires a distinctive IP deal with certai
- ListView 的position不正确的时如何处理