用c语言实现读取配置文件源码
2017-02-02 10:42
423 查看
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> /* #ip ip:192.168.0.0.1 #port port:8888 */ /*读取配置文件*/ void test() { FILE *fp = fopen("config.txt", "r"); if (fp == NULL) { return; } char line[1024] = { 0 }; while (!feof(fp)) { /*初始化line*/ memset(line, 0, 1024); fgets(line, 1024, fp); if (line[0] == '#') { continue; } int len = strlen(line); /*查找冒号的位置*/ char *pos = strchr(line, ':'); if (pos == NULL) { continue; } char key[64] = { 0 }; char val[64] = { 0 }; /*消除不必要的换行*/ int offset = 1; if (line[len - 1] == '\n') { offset = 2; } /*截取key,val值*/ strncpy(key, line, pos - line); strncpy(val, pos + 1, line + len - offset - pos); printf("%s -> %s\n", key, val); } } int main() { test(); system("pause"); return 0; }
相关文章推荐
- 读取到配置文件的C语言的接口实现
- 读取到配置文件的C语言的接口实现
- Linux环境用C语言实现读取配置文件来区分产品的多个版本以及多个功能
- 读取到配置文件的C语言的接口实现
- 读取配置文件[方式一]之纯C语言实现
- C语言实现的配置文件读取功能,喜欢的拿去用.
- 可实现自动重载配置文件读取类
- 三种方式实现Flex读取XML配置文件
- C语言读取配置文件
- 从配置文件里读取数据,实现多数据库连接
- 读取配置文件和自定义配置文件(python实现)
- 从配置文件里读取数据,实现多数据库连接
- 自己写BeanFactory,实现读取配置文件,并根据发射创建对象。
- dicom文件dir的读取C语言实现
- 读取配置文件和自定义配置文件(python实现)
- PHP源码:读取 ini 文件配置信息
- c/c++: 读取配置文件(文本)内容的简单实现
- C# 读取保存App.config配置文件的完整源码参考
- JFig读取配置文件,实现动态加载
- 注册表实现自启动,以及读取配置文件