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语言读写配置文件--转载的更多相关文章

  1. Python自动化测试 -ConfigParser模块读写配置文件

    C#之所以容易让人感兴趣,是因为安装完Visual Studio, 就可以很简单的直接写程序了,不需要做如何配置. 对新手来说,这是非常好的“初体验”, 会激发初学者的自信和兴趣. 而有些语言的开发环 ...

  2. R语言读写中文编码方式

    最近遇到一个很头疼的事,就是 R语言读写中文编码方式.在网上找到了一篇博文,谢谢博主的精彩分享,让我很快解决了问题,在此也分享一下 R语言读写数据的方法很多,这里主要是我在使用read.csv/rea ...

  3. Python-通过configparser读写配置文件

    Python读写配置文件: 1.创建配置文件(文件名以.conf或.ini结束的文件表示配置文件) 2.导入所需模块 OS, configparser >>> import os & ...

  4. 基于Python的接口自动化实战-基础篇之读写配置文件

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

  5. 用ConfigParser模块读写配置文件——Python

    对于功能较多.考虑用户体验的程序,配置功能是必不可少的,如何存储程序的各种配置? 1)可以用全局变量,不过全局变量具有易失性,程序崩溃或者关闭之后配置就没了,再者配置太多,将变量分配到哪里也是需要考虑 ...

  6. 使用ConfigurationManager类读写配置文件

    使用ConfigurationManager类 读写配置文件app.config,以下为代码: view plaincopy to clipboard print? using System; usi ...

  7. Python自动化测试 (二) ConfigParser模块读写配置文件

    ConfigParser 是Python自带的模块, 用来读写配置文件, 用法及其简单. 直接上代码,不解释,不多说. 配置文件的格式是: []包含的叫section,    section 下有op ...

  8. C读写配置文件

    在项目开发中,经常需要读取应用配置文件的初始化参数,用于应用在启动前进行一些初始化配置.比如:Eclipse,参数项包含主题.字体大小.颜色.Jdk安装位置.自动提示等.Eclispe配置的文件格式是 ...

  9. python:实例化configparser模块读写配置文件

    之前的博客介绍过利用python的configparser模块读写配置文件的基础用法,这篇博客,介绍下如何实例化,方便作为公共类调用. 实例化的好处有很多,既方便调用,又降低了脚本的维护成本,而且提高 ...

随机推荐

  1. Linux Socket - UDP链接包

    LINUX UDP SOCKET 01 UDP号绑定会报错吗? 会的,提示Address is using,本地的没有区别 UDP不需要发起链接,不知道是不是连接成功 client的IP地址和端口号不 ...

  2. 如何修改TFS 2013中工作项附件大小限制

    默认情况下,TFS工作项的附件大小限制为4MB.我们可以通过调用TFS提供的Web Service将这个限制调整最高到2GB. 调整这个设置的必备条件是你需要拥有TFS应用层管理员的权限.下面来看看如 ...

  3. TSQL--INT转换成指定长度字符串

    -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ...

  4. .net 开发者尝试Apache Spark™

    本文编译自一篇msdn magazine的文章,原文标题和链接为: Test Run - Introduction to Spark for .NET Developers https://msdn. ...

  5. jenkins启动失败,提示Starting Jenkins Jenkins requires Java8 or later, but you are running 1.7.0

    # 背景 centos安装jenkins后,先启动jenkins服务,结果报错如下: 但自己明明已经安装了java8的 # 解决方法 既然安装了java8的话,那么证明是jenkins启动的是还是用的 ...

  6. 解决IE8不支持console

    解决IE8不支持console,代码中包含console时会报错. //解决 IE8 不支持console window.console = window.console || (function ( ...

  7. C# 使用ProcessStartInfo调用exe获取不到重定向数据的解决方案

    emmmmm,最近在研究WFDB工具箱,C语言写的,无奈本人C语言功底不够,只想直接拿来用,于是打算通过ProcessStartInfo来调取编译出来的exe程序获取输出. 一开始就打算偷懒,从园子里 ...

  8. manual start user profile import

    2 Sign in to vote Thanks Trevor, Finally created the task scheduled with this command: Sync Incremen ...

  9. Android 如何查看源码 (eclipse 按住 ctrl )

    首先要确认 Android SDK Manager 下载并安装了 sources.然后在代码中按住 ctrl 在点一个类名, 如果打开的页面是找不到源码,就点那个按钮,然后找到源码所在的文件夹,就可以 ...

  10. BZOJ4012 [HNOI2015]开店 (动态点分治)

    Description 风见幽香有一个好朋友叫八云紫,她们经常一起看星星看月亮从诗词歌赋谈到 人生哲学.最近她们灵机一动,打算在幻想乡开一家小店来做生意赚点钱.这样的 想法当然非常好啦,但是她们也发现 ...