使用C语言读取properties文件V1.0
来源:互联网 发布:windows文件共享 编辑:程序博客网 时间:2024/05/13 11:16
本程序使用C语言读取类似以下格式的properties文件。
path = /etc/wgetrc
launch_on_start = true
下一版目标:
(1)使用指针代替二维数据或者二维数据的容量减少至最低要求。
(2)忽略所有空格,忽略空行及注释行
(3)头文件规范写法。
文件1:main.c
#include <stdio.h>#include "read_properties.h"int main(void){ char names[100][100], values[100][100]; read_properties("/home/lujinhong/scripts/projects/read_properties_file/test.properties", names, values); return 0;}
文件2:read_properties.h
void read_properties(char *pathname, char names[100][100], char values[100][100]);
文件3:read_properties.c
/******************************************************************** * This file is used to read the names and values from a properties file, * and store them in an array. * * ******************************************************************/#include "read_properties.h"#include <stdio.h>#include <unistd.h>#include "utils.h"void read_properties(char *pathname, char names[100][100], char values[100][100]){ FILE *file; char line[100]; int i = 0; file = fopen(pathname, "r"); while(fgets(line, 100, file)){ printf("%s", line); //just for test, delete it later. parseline(line, names[i], values[i]); i++; } fclose(file);}
文件4:utils.h
void parseline(char *line, char *name, char *value);
文件5:utils.c
/*********************************************************** * Parse content of the line, and store the name and value. * line example: path=/etc/wgetrc * * *********************************************************/void parseline(char *line, char *name, char *value){ int length = 0, equal = 1; //equal will record the location of the '=' char *begin; length = strlen(line); for(begin = line; *begin != '=' && equal <= length; begin ++){ equal++; } strncpy(name, line, equal - 1); line+=equal; strncpy(value, line, length - equal); printf("name = %s value = %s\n", name, value); //just for test, delete it later.}
运行结果:
path = /etc/wgetrcname = path value = /etc/wgetrclaunch_on_boot = truename = launch_on_boot value = true
- 使用C语言读取properties文件V1.0
- 使用C语言读取properties文件V1.0
- java 读取properties文件,运用 使用properties
- 使用Properties读取XML文件
- 使用spring读取properties文件
- 使用C语言读取bmp文件数据
- Properties读取properties文件
- Properties 读取 Properties文件
- C语言文件读取
- C语言----文件读取
- C语言读取文件
- C语言读取文件
- 使用J2SEAPI读取Properties文件的方法
- 使用common-configuration读取xml,properties文件
- 使用common-configuration读取xml,properties文件
- 使用单例模式读取Properties文件
- 使用脚本运行程序读取.properties文件
- Spring使用程序方式读取properties文件
- 彻底解决 Ubuntu 10.04 对部分声卡不支持或耳机无声的问题
- 怎样花两年时间去面试一个人
- C#基本图像处理
- 地理科学国内外核心期刊汇总
- zend studio 中文编码GB2312的乱码解决方法
- 使用C语言读取properties文件V1.0
- JAVA 实现 HTTP文件下载
- ListView判断其内容已滚动到最顶部或者最底部
- Android之Adapter用法总结
- Linux:Ubuntu 11.04下安装极点五笔输入法
- 性能测试知多少---吞吐量
- 将移动应用托管到大型云平台是趋势
- 快递物流行业:数据增量下载的实现
- 虚拟化VMware简介10——Distrbuted Switch (分布式交换机)简介