用c语言实现读取配置文件源码
来源:互联网 发布:node socket.io聊天室 编辑:程序博客网 时间:2024/05/21 09:25
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/*#ipip:192.168.0.0.1#portport: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;}
0 0
- 用c语言实现读取配置文件源码
- 用C语言读取配置文件
- Linux C语言实现读取ini配置文件
- C语言读取配置文件
- C语言读取配置文件
- C语言读取配置文件
- C语言读取配置文件
- Linux下用C语言读取配置文件
- 读取配置文件[方式一]之纯C语言实现
- 读取到配置文件的C语言的接口实现
- 读取到配置文件的C语言的接口实现
- window下C语言实现读取config.ini配置文件
- C语言读取配置文件例子
- C语言读取配置文件代码
- C语言实现的配置文件读取功能,喜欢的拿去用.
- 【C/C++】C语言读取简单配置文件
- C语言读取类unix风格配置文件
- 网上找的c语言读取配置文件
- Effective Java 读书笔记——41:慎用重载
- poj 3190 Stall Reservations
- Pycharm中html模板不能用jinja2标签
- Spotlight 监控工具使用
- 微信小程序支付
- 用c语言实现读取配置文件源码
- According to TLD or attribute directive in tag file, attribute items does not accept any expression
- 蓝桥杯C语言B组-奖券数目
- 使用Maven创建Java项目
- 二叉树,前序,中序,后序遍历的具体实现
- SSH网上商城--Struts2框架中文件的上传
- ERROR in ./~/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.eot Module parse fai
- 10 条提升 Android 性能的建议
- welcome to my blog..