[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"{
#definedllexport __declspec(dllexport) jmp_buf Jmp_Buf;
int E;
#defineException 0x00000#definee Exception#definetry if(!(E=setjmp(Jmp_Buf)))#definelast_error() E#definecatch(val) else#definethrow(val) longjmp(Jmp_Buf,val)#definecheck(expersion) assert(expersion)#defineGetError() errno dllexport voidsig_usr(int);
dllexport char* getTime();
} #else#definedllexport __declspec(dllexport) jmp_buf Jmp_Buf;
int E;
#defineException 0x00000#definee Exception34#definetry if(!(E=setjmp(Jmp_Buf)))35#definelast_error() E36#definecatch(val) else#definethrow(val) longjmp(Jmp_Buf,val)#definecheck(expersion) assert(expersion)#defineGetError() errno dllexport voidsig_usr(int);
dllexport char* getTime(); #endif[2].[代码] File.h 跳至 [1] [2] [3]
#include
[3].[代码] File.c 跳至 [1] [2] [3]
#include "File.h"#include
{
intflag=;
char buffer[SIZE];
FILE *file=fopen(filename,"r");
try {
if(file==NULL)
{
flag=;
throw(flag);
}
else {
while(fgets(buffer,SIZE,file)!=NULL)
{
inti=,j=,len=strlen(key);
while(buffer[i]!='\') {
if(buffer[i]=='$'&&buffer[i+len+]=='=')
{
j=i+len+;
while(buffer[j]!='\'&&buffer[j]!=';') {
inth=;
if(buffer[i+]==key[i])
{
//printf("%c",buffer[j]); value[j-i-len-]=buffer[j];
}
j++;
}
break;
}
elseif(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;
}
intwrite_file(char* filename,char* key,char* value)
{
intflag=;
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;
}
intwrite_section(char* filename,char* section)
{
intflag=;
FILE* file=NULL;
try {
file=fopen(filename,"a");
if(file!=NULL)
{
fprintf(file,"[%s]\n",section);
}
else {
intflag=;
throw(flag);
}
}
catch(Exception)
{
printf("can't open file %s",filename);
exit();
}
fflush(file);
fclose(file);
return flag;
}int release()
{
intflag=;
return flag;
}intread_section(char* filename)
{
return ;
}intgetAuthor(char* value)
{
charauthor[]="武汉软件工程职业学院计算机应用系孟德军";
inti=;
for(i=;i
{
value[i]=author[i];
}
return ;
}voidgetVersion(char* value)
{
charversion[]="////";
inti=;
for(i=;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();
}