最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C語(yǔ)言讀寫(xiě)配置文件的方法

 更新時(shí)間:2015年07月21日 15:16:10   作者:華宰  
這篇文章主要介紹了C語(yǔ)言讀寫(xiě)配置文件的方法,包括C語(yǔ)言讀寫(xiě)ini配置文件所涉及的文件讀寫(xiě)技巧,以及完整的源文件及頭文件實(shí)現(xiàn)方法,需要的朋友可以參考下

本文實(shí)例講述了C語(yǔ)言讀寫(xiě)配置文件的方法。分享給大家供大家參考。具體如下:

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); 
//寫(xiě)配置文件. 
int write_file(char* filename,char* key,char* value); 
//釋放文件. 
int release(); 
//寫(xiě)入節(jié). 
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=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]="武漢軟件工程職業(yè)學(xué)院計(jì)算機(jī)應(yīng)用系"; 
 int i=0; 
 for(i=0;i<strlen(author);i++) 
 { 
 value[i]=author[i]; 
 } 
 return 0; 
} 
void getVersion(char* value) 
{ 
 char version[128]="2009//05//01"; 
 int i=0; 
 for(i=0;i<strlen(version);i++) 
 { 
 value[i]=version[i]; 
 } 
} 
/************************************************************************** 
void main() 
{ 
 char* str=NULL; 
 char author[120]; 
 char buffer[128]; 
 char buffer1[128]; 
 char buffer2[128]; 
 read_file("F:\\exercise\\C++!C\\sys.ini","password",buffer); 
 read_file("F:\\exercise\\C++!C\\sys.ini","username",buffer1); 
 read_file("F:\\exercise\\C++!C\\sys.ini","driver",buffer2); 
 printf("password=%s\n",buffer); 
 printf("\n"); 
 printf("username=%s\n",buffer1); 
 printf("\n"); 
 printf("driver=%s\n",buffer2); 
 getAuthor(author); 
 printf("\n"); 
 printf("author=%s",author); 
 release(); 
}

希望本文所述對(duì)大家的C語(yǔ)言程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Opencv實(shí)現(xiàn)拼圖板游戲

    Opencv實(shí)現(xiàn)拼圖板游戲

    這篇文章主要為大家詳細(xì)介紹了Opencv實(shí)現(xiàn)拼圖板小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • C/C++中命名空間(namespace)詳解及其作用介紹

    C/C++中命名空間(namespace)詳解及其作用介紹

    今天小編就為大家分享一篇關(guān)于C++命名空間namespace的介紹與使用,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2021-09-09
  • 淺談關(guān)于指針作為參數(shù)并改變它的值的問(wèn)題

    淺談關(guān)于指針作為參數(shù)并改變它的值的問(wèn)題

    這篇文章介紹了關(guān)于指針作為參數(shù)并改變它的值的問(wèn)題,有需要的朋友可以參考一下
    2013-10-10
  • C++中函數(shù)重載詳解

    C++中函數(shù)重載詳解

    大家好,本篇文章主要講的是C++中函數(shù)重載詳解,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下
    2022-02-02
  • opencv實(shí)現(xiàn)多張圖像拼接

    opencv實(shí)現(xiàn)多張圖像拼接

    這篇文章主要為大家詳細(xì)介紹了opencv實(shí)現(xiàn)多張圖像拼接功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • C++實(shí)現(xiàn)本地TCP通訊的示例代碼

    C++實(shí)現(xiàn)本地TCP通訊的示例代碼

    這篇文章主要為大家詳細(xì)介紹了C++如何利用TCP技術(shù),實(shí)現(xiàn)本地ROS1和ROS2的通訊,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-02-02
  • vs2019創(chuàng)建WebService服務(wù)的實(shí)現(xiàn)

    vs2019創(chuàng)建WebService服務(wù)的實(shí)現(xiàn)

    這篇文章主要介紹了vs2019創(chuàng)建WebService服務(wù)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • 詳解C/C++ Linux出錯(cuò)處理函數(shù)(strerror與perror)的使用

    詳解C/C++ Linux出錯(cuò)處理函數(shù)(strerror與perror)的使用

    我們知道,系統(tǒng)函數(shù)調(diào)用不能保證每次都成功,必須進(jìn)行出錯(cuò)處理,這樣一方面可以保證程序邏輯正常,另一方面可以迅速得到故障信息。本文主要為大家介紹兩個(gè)出錯(cuò)處理函數(shù)(strerror、perror)的使用,需要的可以參考一下
    2023-01-01
  • C語(yǔ)言獲取Shell返回結(jié)果的實(shí)現(xiàn)方法

    C語(yǔ)言獲取Shell返回結(jié)果的實(shí)現(xiàn)方法

    下面小編就為大家?guī)?lái)一篇C語(yǔ)言獲取Shell返回結(jié)果的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-07-07
  • vscode工程中c_cpp_properties.json文件作用詳細(xì)說(shuō)明

    vscode工程中c_cpp_properties.json文件作用詳細(xì)說(shuō)明

    c_cpp_properties.json是Visual Studio Code的一個(gè)配置文件,用于定義C/C++編譯器的路徑、默認(rèn)包含路徑和預(yù)處理器定義,這篇文章主要給大家介紹了關(guān)于vscode工程中c_cpp_properties.json文件作用詳細(xì)說(shuō)明的相關(guān)資料,需要的朋友可以參考下
    2024-08-08

最新評(píng)論

库伦旗| 民乐县| 景谷| 恩施市| 惠安县| 上高县| 峡江县| 沂源县| 会同县| 建瓯市| 邯郸县| 竹溪县| 连山| 吉安市| 类乌齐县| 资源县| 监利县| 涪陵区| 陵水| 武乡县| 怀宁县| 东方市| 大田县| 绥阳县| 寿阳县| 扎兰屯市| 林芝县| 色达县| 襄垣县| 土默特左旗| 巴楚县| 浪卡子县| 广饶县| 秭归县| 沾化县| 平阳县| 合川市| 苍南县| 嘉黎县| 广东省| 神农架林区|