- 浏览: 16978 次
最新评论
C语言读写配置文件
2011年03月04日
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 #include #include #include #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 int read_file(char* filename,char* key,char* value) { int flag=0; char buffer[SIZE]; FILE *file=fopen(filename,"r"); try { if(file==NULL) { flag=1; throw(flag); } else { while(fgets(buffer,SIZE,file)!=NULL) { int i=0,j=0,len=strlen(key); while(buffer[i]!='\0') { if(buffer[i]=='$'&&buffer[i+len+1]=='=') { j=i+len+2; while(buffer[j]!='\0'&&buffer[j]!=';') { int h=0; if(buffer[i+1]==key[i]) { //printf("%c",buffer[j]); value[j-i-len-2]=buffer[j]; } j++; } break; } else if(buffer[i]=='/'&&buffer[i+1]=='/'||buffer[i]=='; ') { break; //comment } i++; } } } } catch(Exception) { flag=2; fclose(file); printf("can't open file %s",filename); exit(1); } fflush(file); fclose(file); return flag; } int write_file(char* filename,char* key,char* value) { int flag=0; FILE* file; file=fopen(filename,"a"); try { if(file==NULL) { flag=1; throw(flag); } fprintf(file,"$%s=%s\n",key,value); } catch(Exception) { printf("Can't write file %s",filename); exit(1); } fflush(file); fclose(file); return flag; } int write_section(char* filename,char* section) { int flag=0; FILE* file=NULL; try { file=fopen(filename,"a"); if(file!=NULL) { fprintf(file,"[%s]\n",section); } else { int flag=1; throw(flag); } } catch(Exception) { printf("can't open file %s",filename); exit(0); } fflush(file); fclose(file); return flag; } int release() { int flag=1; return flag; } int read_section(char* filename) { return 0; } int getAuthor(char* value) { char author[128]="武汉软件工程职业学院计算机应用系孟德军"; int i=0; for(i=0;i typedef (* write)(char* filename,char* key,char* value); typedef (* writes)(char* filename,char* value); typedef (* read)(char* filename,char* key,char* value); HINSTANCE hInstance; write write_file; writes write_section; read read_file; char buffer[128]; char buffer1[128]; void main() { hInstance=LoadLibrary("File.dll"); if(hInstance!=NULL) { write_file=(write)GetProcAddress(hInstance,"write_ file"); write_section=(writes)GetProcAddress(hInstance,"wr ite_section"); read_file=(read)GetProcAddress(hInstance,"read_fil e"); write_section("config.ini","mysql"); write_file("config.ini","username","root"); write_file("config.ini","password","admin"); write_file("config.ini","driverClassName","com.mys ql.jdbc.Driver"); write_file("config.ini","url","jdbc:mysql://localh ost:3306/user"); read_file("config.ini","username",buffer); printf("username=%s",buffer); read_file("config.ini","password",buffer1); printf("password=%s",buffer1); } else { printf("can't load dynamic file File.dll"); } FreeLibrary(hInstance); }
发表评论
-
第7章 委托和事件
2012-01-20 01:08 652第7章 委托和事件 2011 ... -
史上最强劲之android模拟器命令详解
2012-01-20 01:08 754史上最强劲之android模拟器命令详解 2010年11月2 ... -
android_adb命令
2012-01-20 01:08 665android_adb命令 2010年12月17日 An ... -
虚拟研讨会:移动Web应用开发技术最新动态
2012-01-20 01:08 691虚拟研讨会:移动Web应用 ... -
编译Boost 1.38
2012-01-20 01:08 631编译Boost 1.38 2010年10月28日 首先, ... -
程序工具
2012-01-19 08:57 544程序工具 2010年10月15日 开发(Developm ... -
arm linux 编译环境建立(文摘)
2012-01-19 08:57 454arm linux 编译环境建立(文摘) 2011年02月2 ... -
计算机概论
2012-01-19 08:57 520计算机概论 2011年04月26日 import 我.认 ... -
探索C++的秘密之一详解extern "C"
2012-01-19 08:57 593探索C++的秘密之一详解extern "C" ... -
库文件和系统调用的区别
2012-01-19 08:57 588库文件和系统调用的区 ... -
国产机免流下载网上资源方法(仅限移动用户
2012-01-17 01:27 482国产机免流下载网上资源方法(仅限移动用户 2011年06月0 ... -
2010-11-15
2012-01-17 01:27 5612010-11-15 2010年11月15日 ... -
2011-1-20
2012-01-17 01:27 6772011-1-20 2011年01月20日 ... -
电脑蓝屏自动关机故障的检修方法
2012-01-17 01:27 759电脑蓝屏自动关机故障的检修方法 2011年09月23日 ... -
liniux学习
2012-01-17 01:27 870liniux学习 2010年06月08日 ... -
身历六帝宠不衰
2012-01-15 20:08 585身历六帝宠不衰 2009年0 ... -
唐太宗,霸占过隋炀帝之妻吗?(图)
2012-01-15 20:08 502唐太宗,霸占过隋炀帝之 ... -
传奇美人之萧皇后
2012-01-15 20:08 585传奇美人之萧皇后 2010年06月03日 命运奇特的女人 ... -
花果山的快乐之家――邻水中学实习队
2012-01-15 20:08 559花果山的快乐之家――邻水中学实习队 2009年06月08日 ... -
Power designer 15生成sql server 2005/2008列注释
2012-01-11 12:17 623Power designer 15生成sql server 2 ...
相关推荐
使用纯C语言写的读写ini格式配置文件示例,VC6编译,代码和注释详细。封装合理,可快速集成到其它项目。
主要介绍了C语言读写配置文件的方法,包括C语言读写ini配置文件所涉及的文件读写技巧,以及完整的源文件及头文件实现方法,需要的朋友可以参考下
用纯C语言实现配置文件的读写函数,可代替WritePrivateProfileString和GetPrivateProfileString函数.
用c语言实现配置文件读写,完整的函数,适当的注释,值得的参考!
有了它,就不用为在linux下读写配置文件烦恼了。 经实际项目使用测试,绝对好用
利用纯C语言实现的配置文件.ini读写函数,可跨平台使用。功能与Windows API函数 WritePrivateProfileString 和GetPrivateProfileString 一样
这是个不错的c代码,可以用在linux环境下c语言读写配置文件,转给大家下载。
纯c读写ini配置文件 用c/c++读写ini配置文件有不少第三方的开源库,如iniparser、libini、rwini、UltraLightINIParser等,但都不理想,往往代码较大、功能较弱、 接口使用不方便。尤其在大小写处理、前后空格、各种...
在Windows下可以用GetPrivateProfileString或GetPrivateProfileInt方便读取.ini配置文件内容,自己尝试写了一下这个函数。还有一些bug,后面慢慢改。
C语言配置文件读写.zip
标准C/C++读写配置文件类,读写ini文件,加入工程就可以用. 非常完美的封装类,利用SET容器储存,速度非常快。
使用标准C库写的INI读写文件,支持INI文件注释。 当前版本在WINDOWS下用codeblock编译测试通过,稍作修改(知道linux windows下换行符的差别即可)即可移植到linux系统中。欢迎交流!
WINCE下读写INI配置文件,支持ANSI及UNICODE编码。C语言实现,高效简洁,调用接口及实现效果与系统API近乎一致。
C语言实现的INI文件读写操作是软件开发中常用的一种配置管理技术。INI文件以其简单的结构和易于编辑的特性,成为了存储程序设置和配置信息的首选格式。通过使用C语言编写的读写操作函数,开发者可以轻松地在程序中...
ini 使用c语言读写ini 使用c语言读写ini 使用c语言读写ini 使用c语言读写ini 使用c语言读写ini 使用c语言读写ini 使用c语言读写ini 使用c语言读写ini 使用c语言读写ini 使用c语言读写ini 使用c语言读写ini 使用c语言...
这个代码用于读写配置文件,分为Section、Key、Value三部分,用C语言编写,适合各种应用场合,非常实用,代码精简高效,单片机也能使用,linux、windos就更不在话下了。
在LINUX平台下C语言实现的配置文件的读写,非常方便,可用于嵌入式开发。 写配置函数实现:int WritePrivateProfileString(char *section,char *key,char *val,char *filePath) 读配置函数实现:int ...
C语言写的读取INI信息例程,对自己的ini文件操作的Api例程.GetiniString_App
linux c,ini配置文件读写模块,主要用于对ini配置文件进行对鞋操作