C语言读写配置文件--转载
http://www.oschina.net/code/snippet_4873_2503
[].[代码] CException.h 跳至 [] [] []
/************************************************************************/
/* make0000@msn.com */
/************************************************************************/
/************************************************************************/
#include "stdio.h"
#include "conio.h"
#include "signal.h"
#include "setjmp.h"
#include "assert.h"
#ifdef __cplusplus
#include "iostream"
#include "exception"
extern "C"{ #define dllexport __declspec(dllexport)
jmp_buf Jmp_Buf;
int E;
#define Exception 0x00000
#define e Exception
#define try if(!(E=setjmp(Jmp_Buf)))
#define last_error() E
#define catch(val) else
#define throw(val) longjmp(Jmp_Buf,val)
#define check(expersion) assert(expersion)
#define GetError() errno
dllexport void sig_usr(int);
dllexport char* getTime();
}
#else
#define dllexport __declspec(dllexport)
jmp_buf Jmp_Buf;
int E;
#define Exception 0x00000
#define e Exception #define try if(!(E=setjmp(Jmp_Buf))) #define last_error() E #define catch(val) else
#define throw(val) longjmp(Jmp_Buf,val)
#define check(expersion) assert(expersion)
#define GetError() errno
dllexport void sig_usr(int);
dllexport char* getTime();
#endif
[].[代码] File.h 跳至 [] [] []
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#define SIZE 128
#include "CException.h"
#define export __declspec(dllexport)
//读取配置文件.
int read_file(char* filename,char* key,char* value);
//写配置文件.
int write_file(char* filename,char* key,char* value);
//释放文件.
int release();
//写入节.
int write_section(char* filename,char* section);
int read_section(char* filename);
int getAuthor(char* value);
void getVersion(char* value);
[].[代码] File.c 跳至 [] [] [] #include "File.h" #include <string.h> int read_file(char* filename,char* key,char* value) { int flag=; char buffer[SIZE]; FILE *file=fopen(filename,"r"); try { if(file==NULL) { flag=; throw(flag); } else { while(fgets(buffer,SIZE,file)!=NULL) { int i=,j=,len=strlen(key); while(buffer[i]!='\') { if(buffer[i]=='$'&&buffer[i+len+]=='=') { j=i+len+; while(buffer[j]!='\'&&buffer[j]!=';') { int h=; if(buffer[i+]==key[i]) { //printf("%c",buffer[j]); value[j-i-len-]=buffer[j]; } j++; } break; } else if(buffer[i]=='/'&&buffer[i+]=='/'||buffer[i]==';') { break; //comment } i++; } } } } catch(Exception) { flag=; fclose(file); printf("can't open file %s",filename); exit(); } fflush(file); fclose(file); return flag; } int write_file(char* filename,char* key,char* value) { int flag=; FILE* file; file=fopen(filename,"a"); try { if(file==NULL) { flag=; throw(flag); } fprintf(file,"$%s=%s\n",key,value); } catch(Exception) { printf("Can't write file %s",filename); exit(); } fflush(file); fclose(file); return flag; } int write_section(char* filename,char* section) { int flag=; FILE* file=NULL; try { file=fopen(filename,"a"); if(file!=NULL) { fprintf(file,"[%s]\n",section); } else { int flag=; throw(flag); } } catch(Exception) { printf("can't open file %s",filename); exit(); } fflush(file); fclose(file); return flag; } int release() { int flag=; return flag; } int read_section(char* filename) { return ; } int getAuthor(char* value) { char author[]="武汉软件工程职业学院计算机应用系孟德军"; int i=; for(i=;i<strlen(author);i++) { value[i]=author[i]; } return ; } void getVersion(char* value) { char version[]="////"; int i=; for(i=;i<strlen(version);i++) { value[i]=version[i]; } } /************************************************************************** void main() { char* str=NULL; char author[]; char buffer[]; char buffer[]; char buffer[]; read_file("F:\\exercise\\C++!C\\sys.ini","password",buffer); read_file("F:\\exercise\\C++!C\\sys.ini","username",buffer); read_file("F:\\exercise\\C++!C\\sys.ini","driver",buffer); printf("password=%s\n",buffer); printf("\n"); printf("username=%s\n",buffer); printf("\n"); printf("driver=%s\n",buffer); getAuthor(author); printf("\n"); printf("author=%s",author); release(); }
C语言读写配置文件--转载的更多相关文章
- Python自动化测试 -ConfigParser模块读写配置文件
C#之所以容易让人感兴趣,是因为安装完Visual Studio, 就可以很简单的直接写程序了,不需要做如何配置. 对新手来说,这是非常好的“初体验”, 会激发初学者的自信和兴趣. 而有些语言的开发环 ...
- R语言读写中文编码方式
最近遇到一个很头疼的事,就是 R语言读写中文编码方式.在网上找到了一篇博文,谢谢博主的精彩分享,让我很快解决了问题,在此也分享一下 R语言读写数据的方法很多,这里主要是我在使用read.csv/rea ...
- Python-通过configparser读写配置文件
Python读写配置文件: 1.创建配置文件(文件名以.conf或.ini结束的文件表示配置文件) 2.导入所需模块 OS, configparser >>> import os & ...
- 基于Python的接口自动化实战-基础篇之读写配置文件
引言 在编写接口自动化测试脚本时,有时我们需要在代码中定义变量并给变量固定的赋值.为了统一管理和操作这些固定的变量,咱们一般会将这些固定的变量以一定规则配置到指定的配置文件中,后续需要用到这些变量和变 ...
- 用ConfigParser模块读写配置文件——Python
对于功能较多.考虑用户体验的程序,配置功能是必不可少的,如何存储程序的各种配置? 1)可以用全局变量,不过全局变量具有易失性,程序崩溃或者关闭之后配置就没了,再者配置太多,将变量分配到哪里也是需要考虑 ...
- 使用ConfigurationManager类读写配置文件
使用ConfigurationManager类 读写配置文件app.config,以下为代码: view plaincopy to clipboard print? using System; usi ...
- Python自动化测试 (二) ConfigParser模块读写配置文件
ConfigParser 是Python自带的模块, 用来读写配置文件, 用法及其简单. 直接上代码,不解释,不多说. 配置文件的格式是: []包含的叫section, section 下有op ...
- C读写配置文件
在项目开发中,经常需要读取应用配置文件的初始化参数,用于应用在启动前进行一些初始化配置.比如:Eclipse,参数项包含主题.字体大小.颜色.Jdk安装位置.自动提示等.Eclispe配置的文件格式是 ...
- python:实例化configparser模块读写配置文件
之前的博客介绍过利用python的configparser模块读写配置文件的基础用法,这篇博客,介绍下如何实例化,方便作为公共类调用. 实例化的好处有很多,既方便调用,又降低了脚本的维护成本,而且提高 ...
随机推荐
- can not update ICEAuthority file mint或则ubuntu
引起的原因为:设置了用户自动登录引起的. 1)去除自动登录 2)删除 ICEAuthority文件. 即可.
- (zxing.net)二维码Data Matrix的简介、实现与解码
一.简介 Data Matrix 二维条码原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于1989年发明.Data-Matri ...
- JZOJ6096 森林
题目传送门 Description 我们定义对一棵树做一次变换的含义为:当以 1 号节点为根时,交换两个互相不为祖先的点的子树: 一棵树的权值为对它进行至多一次变换能得到的最大直径长度: 初始时 ...
- 使用Anaconda的python安装虚拟环境是出现错误:python -m venv venvdir----Error: Command '['D:\\Development\\Django\\test\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit
在创建python虚拟环境的时候,如果使用的是Anaconda中集成的python -m venv venvdir就会出现不能安装pip的错误,原因是Anaconda没有ensurepip, 解决办法 ...
- MyBatis入门程序(基于XML配置)
创建一个简单的MyBatis入门程序,实现对学生信息的增删改查功能(基于XML配置) 一.新建一个Java工程,导入MyBatis核心jar包.日志相关的jar包以及连接Oracle数据库所需驱动包, ...
- JavaScript(汇聚页)
JavaScript对象 String 对象 RegExp 对象 \W 元字符
- 如何在Cordova Android 7.0.0 以下版本集成最新插件 极光插件为例
前提 Cordova Android 7.0.0开始改变了项目安卓平台的架构.新建一个空项目分别添加Android 6.4.0 和 Android 7.0.0平台: cordova platform ...
- 使用Python Pandas处理亿级数据
在数据分析领域,最热门的莫过于Python和R语言,此前有一篇文章<别老扯什么Hadoop了,你的数据根本不够大>指出:只有在超过5TB数据量的规模下,Hadoop才是一个合理的技术选择. ...
- python基础知识梳理-----4基本数据类型,list ,tuple 操作 ,增删该查,以及其他功能函数
一:列表的增加 1: append() lis = ['张三','李四','王二码子','李鹏智障'] lis.append('赵武') # 这种加法是放在最后 print(lis) 输出 ...
- mybatis的执行流程
1.SqlSessionFactoryBuilder与SqlSessionFactory 我们一般在使用mybatis是都会通过new SqlSessionFactoryBuilder.build(. ...