http://www.oschina.net/code/snippet_4873_2503

[1].[代码] CException.h 跳至 [1] [2] [3]
/************************************************************************/
/*             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
34#define try if(!(E=setjmp(Jmp_Buf)))
35#define last_error() E
36#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
[2].[代码] File.h 跳至 [1] [2] [3]
#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);
[3].[代码] File.c 跳至 [1] [2] [3]#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语言读写配置文件--转载相关推荐

  1. C语言读写ini、json、csv文件

    运用C语言读写配置文件中.ini或.json或.csv合适的文件方法 一.读写ini格式的配置文件 1.读ini文件 //读ini文件 void readIniFile(){//1.创建一个字典指针d ...

  2. 易语言写c盘配置文件,易语言 读写配置项(ini配置文件)源码

    简介 易语言 读写配置项(ini配置文件)源码 源码 .版本 2 .支持库 iext .程序集 窗口程序集_启动窗口 .子程序 _按钮1_被单击 .局部变量 账号, 文本型 .局部变量 密码, 文本型 ...

  3. 一个用于读写配置文件的类

    一个用于读写配置文件的类 该类适应读写如下格式的.xml,.config文档 <?xml version="1.0" encoding="utf-8" s ...

  4. 如何在MFC中读写配置文件

    如何在MFC中读写配置文件 在我们写的程序当中,总有一些配置信息需要保存下来,以便完成程序的功能,最简单的办法就是将这些信息写入INI文件中,程序初始化时再读入.具体应用如下: 一.将信息写入.INI ...

  5. python自动化读取和写入文件_基于Python的接口自动化实战-基础篇之读写配置文件...

    引言 在编写接口自动化测试脚本时,有时我们需要在代码中定义变量并给变量固定的赋值.为了统一管理和操作这些固定的变量,咱们一般会将这些固定的变量以一定规则配置到指定的配置文件中,后续需要用到这些变量和变 ...

  6. 自由读写配置文件的艺术[java c++ node](二)

    为何要自己写配置文件 1 解决引入很多库的问题 2 解决流程问题而非语言问题 3 学会简化问题 读写配置文件的知识 一下是一个txt配置文件,注意文件格式,如果我们在utf8 文件下读写,分为两种,一 ...

  7. python读conf配置文件_python读写配置文件操作示例

    本文实例讲述了python读写配置文件操作.分享给大家供大家参考,具体如下: 在用编译型语言写程序的时候,很多时候用到配置文件,作为一个约定的规则,一般用 ini 文件作为配置文件,当然不是绝对的,也 ...

  8. C语言读写bmp位图文件

    bitmap格式图片是未经压缩的,一般24bit位图(即一个像素点以24个二进制位表示). 分别用8个二进制位表示R/G/B三种颜色,这样一共可以表示256*256*256=16777216种颜色. ...

  9. 用C语言读写文本文件

    本节主要讨论如何使用C语言读写文本文件. 本文引用自作者编写的下述图书; 本文允许以个人学习.教学等目的引用.讲授或转载,但需要注明原作者"海洋饼干叔 叔":本文不允许以纸质及电子 ...

最新文章

  1. PHP基础示例:用PHP+Mysql编写简易新闻管理系统
  2. linux mysql 密码文件怎么打开文件,Oracle数据库密码文件创建与使用
  3. c++中list容器
  4. mysql数据库参数
  5. python3 内置方法
  6. 元气骑士如何获得机器人成就皮肤_元气骑士:获得成就叹息之墙,花圃免费开,附带5000蓝币奖励...
  7. MongoDB教程——第2天
  8. ASP.NET页面输出缓存知识
  9. python入门指南 许半仙txt-影帝的脑子坏了
  10. Excel 如何解决把数字格式变成会计格式的问题
  11. 输入框字母自动转换大写
  12. 你学习·我奖励,21天学习挑战赛 | 等你来战
  13. 人到中年,没事多休息,有空多赚钱!
  14. vue 中点击叉号,关闭div的方法
  15. excel手机版_微软开发于手机端的办公软件!
  16. 计算机二级c语言考点解析,2017年计算机二级C语言考点解析
  17. 10种算法一文打尽!基本图表算法的视觉化阐释
  18. VBA For Each循环
  19. 屏幕尺寸,分辨率,ppi换算分析
  20. AToken每日简讯 1.17 星期四

热门文章

  1. 图灵今年的生日礼物,是新版50英镑纸币
  2. AI老大哥,正在看着你
  3. 微信支付:小微商户申请入驻第二步:图片上传
  4. 转换Word文档为PDF文件
  5. JS题目总结:原型链/new/json/MVC/Promise
  6. JS中相等运算符 == 隐式转换
  7. (转)如何在一台电脑上开启多个tomcat 和配置让系统识别哪个具体的tomcat
  8. Windows Server 2012 R2配置ISCSI磁盘共享盘(4)
  9. 6426C Lab6 部署和配置RMS
  10. 根据FileUpload控件名获取上传文件(大小)类型