配置檔案的讀與寫(一)

2021-06-23 05:57:06 字數 1523 閱讀 4743

配置檔案的讀取與寫入總結為如下步驟: 

1.開啟配置檔案 ,獲取根節點指標。

4.關閉配置檔案。

下面進行詳細的介紹:

前提:a .所涉及的標頭檔案:

#include

#include

#include

#include

b.巨集定義 

#define  c_config_device_max_name_len  20

#define  c_config_device_max_address_len 6

#define  file_path   "/home/profile/path/ma_config.xml"

#define null  0

c. 所涉及的列舉型別以及 結構體 

typedef structma_config_info_t;

typedef enumma_config_event_e;

typedef enumma_event_result_e;

c.所涉及的全域性變數

xmldocptr   doc =null;

xmlnodeptr  node = null;

ma_config_info_t  ma_config_info; 

d.函式的宣告

int ma_config_file_open(char* file_path);

int ma_config_file_read_file(void);

int ma_config_read(int event_id ,char* data,int data_length);

int ma_config_file_write(int event_id ,char * data,int data_length);

int ma_config_close(void);

static int ma_read_phone_cfg(xmlnodeptr  node);

static int ma_read_video_cfg(xmlnodeptr  node);

static int ma_phone_set_cfg(int event_id ,char* data,int data_length);

static int ma_video_set_cfg(int event_id , char * data,int data_length);

xmlnodeptr ma_get_video_node(void);

xmlnodeptr ma_get_phone_node(void);

static int  ma_string_to_char(char*,char*,uint );

static int  ma_char_to_string(char*,char*,uint );

e 所需的配置檔案內容如下:

<?xml version="1.0" encoding="utf-8"?>   

00010

0100

huawei

010203040506

讀配置檔案

tchar szpath max path memset szpath,0,sizeof szpath getmodulefilename null,szpath,max path cstring strpath szpath strpath strpath.left strpath.reverse...

讀配置檔案2

資料 host 1 ip 16.173.234.228 port 21,80,873,3306 cpu 10 freemem 3 conconn 1000 checkgw 1 freedisk 10 swapused 30000 host host 2 ip 16.173.235.25 port 2...

Php讀配置檔案

馬永佔,myz,mayongzhan php讀配置檔案 馬永佔,myz,mayongzhan 要讀的格式 php.ini this is demo by 馬永佔 myz global i 1j 2 k 3 self a 11 b 22 c 33 讀的方法 name test4.php date mo...