posts - 45,  comments - 232,  trackbacks - 0

昨天写了个一组ini文件读写函数。提供大家使用,已经在XP+VC7.1和FC6+GCC4.1,ARM9+arm-linux-gcc3.3中测试过了,可以跨平台使用。使用标准C写得,支持C++。源程序可以到:http://www.cppblog.com/Files/dyj057/inifile.zip下载。

 

/* *
*@file             inifile.h
*@cpright        (C)2007 GEC 
*@auther        dengyangjun
*@email        dyj057@gmail.com
*@version        0.1
*@create         2007-1-14 
*@modify        2007-1-14
*@brief            declare ini file operation
*@note
*@history    
*/

#ifndef INI_FILE_H_
#define  INI_FILE_H_

#ifdef __cplusplus
extern   " C "
{
#endif

int  read_profile_string(  const   char   * section,  const   char   * key, char   * value,  int  size,  const   char   * file);
int  read_profile_int(  const   char   * section,  const   char   * key, int  default_value,  const   char   * file);

int  write_profile_string(  const   char   * section,  const   char   * key, const   char   * value,  const   char   * file);

#ifdef __cplusplus
}; 
// end of extern "C" {
#endif

#endif   // end of INI_FILE_H_

 

/* *
*@file             inifile.c
*@cpright        (C)2007 GEC
*@auther        dengyangjun
*@email        dyj057@gmail.com
*@version        0.1
*@create         2007-1-14 
*@modify        2007-1-14
*@brief            implement ini file operation
*@note
*@history    
*/
#include 
< stdio.h >
#include 
< stdlib.h >
#include 
< assert.h >
#include 
< string .h >
#include 
< ctype.h >

#include 
" inifile.h "

#ifdef __cplusplus
extern   " C "
{
#endif

#define  MAX_FILE_SIZE 8096

#define  LEFT_BRACE '['
#define  RIGHT_BRACE ']'

static   int  load_ini_file( const   char   * file,  char   * buf, int   * file_size)
{
    FILE 
* in   =  NULL;
    
int  i = 0 ;
    
* file_size  = 0 ;

    assert(file 
!= NULL);
    assert(buf 
!= NULL);

    
in   =  fopen(file, " r " );
    
if ( NULL  ==   in ) {
        
return   0 ;
    }

    
// load initialization file
     while ((buf[i] = fgetc( in )) != EOF) {
        i
++ ;
        assert( i 
<  MAX_FILE_SIZE);  // file too big
    }
    
    buf[i]
= ' \0 ' ;
    
* file_size  =  i;

    fclose(
in );
    
return   1 ;
}

/*
*<summary></summary>
* <returns>Result of the addtion(int)</returns>
* <param name="x"></param>
* <param name="y"></param>
*/

static   int  isnewline( char  c)
{
    
return  ( ' \n '   ==  c  ||    ' \r '   ==  c ) ?   1  :  0 ;
}
static   int  isend( char  c)
{
    
return   ' \0 ' == c ?   1  :  0 ;
}
static   int  isleftbarce( char  c)
{
    
return  LEFT_BRACE  ==  c ?   1  :  0 ;
}
static   int  isrightbrace( char  c )
{
    
return  RIGHT_BRACE  ==  c ?   1  :  0 ;
}
static   int  parse_file( const   char   * section,  const   char   * key,  const   char   * buf, int   * sec_s, int   * sec_e,
                      
int   * key_s, int   * key_e,  int   * value_s,  int   * value_e)
{
    
const   char   * =  buf;
    
int  i = 0 ;

    assert(buf
!= NULL);
    assert(section 
!=  NULL  &&  strlen(section));
    assert(key 
!=  NULL  &&  strlen(key));

    
* sec_e  =   * sec_s  =   * key_e  =   * key_s  =   * value_s  =   * value_e  =   - 1 ;

    
while ! isend(p[i]) )
    {
        
// find the section
         if ( (  0 == ||   isnewline(p[i - 1 ]) )  &&  isleftbarce(p[i]) )
        {
            
int  section_start = i + 1 ;

            
// find the ']'
             do
            {
                i
++ ;
            }
while ! isrightbrace(p[i])  &&   ! isend(p[i]));

            
if 0   ==  strncmp(p + section_start,section, i - section_start))
            {
                
int  newline_start = 0 ;

                i
++ ;

                
// Skip over space char after ']'
                 while (isspace(p[i]))
                {
                    i
++ ;
                }

                
// find the section
                 * sec_s  =  section_start;
                
* sec_e  =  i;

                
while !  (isnewline(p[i - 1 ])  &&  isleftbarce(p[i]))  &&   ! isend(p[i]) )
                {
                    
int  j = 0 ;
                    
// get a new line
                    newline_start  =  i;

                    
while ! isnewline(p[i])  &&    ! isend(p[i]) )
                    {
                        i
++ ;
                    }
                    
// now i  is equal to end of the line

                    j
= newline_start;

                    
if ( ' ; '   !=  p[j])  // skip over comment
                    {
                        
while (j  <  i  &&  p[j] != ' = ' )
                        {
                            j
++ ;
                            
if ( ' = '   ==  p[j])
                            {
                                
if (strncmp(key,p + newline_start,j - newline_start) == 0 )
                                {
                                    
// find the key ok
                                     * key_s  =  newline_start;
                                    
* key_e  =  j - 1 ;

                                    
* value_s  =  j + 1 ;
                                    
* value_e  =  i;

                                    
return   1 ;
                                }
                            }
                        }
                    }

                    i
++ ;
                }
            }
        }
        
else
        {
            i
++ ;
        }
    }
    
return   0 ;
}

/* *
* @brief read_profile_string <d>retrieves a string from the specified section in an initialization file.
* @param section  <t>const char * <in> <d>name of the section containing the key name.
* @param key  <t>const char *  <in><d>the name of the key whose associated string is to be retrieved.
* @param value <t>char * <out><d>pointer to the buffer that receives the retrieved string.      
* @return <t>int  <n>1 : read success; 0 : read fail.
*/       
int  read_profile_string(  const   char   * section,  const   char   * key, char   * value,   int  size,  const   char   * file)
{
    
char  buf[MAX_FILE_SIZE] = { 0 };
    
int  file_size;
    
int  sec_s,sec_e,key_s,key_e, value_s, value_e;

    
// check parameters
    assert(section  !=  NULL  &&  strlen(section));
    assert(key 
!=  NULL  &&  strlen(key));
    assert(value 
!=  NULL);
    assert(size 
>   0 );
    assert(file 
!= NULL  && strlen(key));

    
if ! load_ini_file(file,buf, & file_size))
        
return   0 ;

    
if ( ! parse_file(section,key,buf, & sec_s, & sec_e, & key_s, & key_e, & value_s, & value_e))
    {
        
return   0 // not find the key
    }
    
else
    {
        
int  cpcount  =  value_e  - value_s;

        
if ( size - 1   <  cpcount)
        {
            cpcount 
=   size - 1 ;
        }
    
        memset(value, 
0 , size);
        memcpy(value,buf
+ value_s, cpcount );
        value[cpcount] 
=   ' \0 ' ;

        
return   1 ;
    }
}


int  read_profile_int(  const   char   * section,  const   char   * key, int  default_value,  const   char   * file)
{
    
char  value[ 32 =  { 0 };
    
if ( ! read_profile_string(section,key,value,  sizeof (value),file))
    {
        
return  default_value;
    }
    
else
    {
        
return  atoi(value);
    }
}

int  write_profile_string(  const   char   * section,  const   char   * key, const   char   * value,  const   char   * file)
{
    
char  buf[MAX_FILE_SIZE] = { 0 };
    
char  w_buf[MAX_FILE_SIZE] = { 0 };
    
int  sec_s,sec_e,key_s,key_e, value_s, value_e;
    
int  value_len  =  ( int )strlen(value);
    
int  file_size;
    FILE 
* out ;

    
// check parameters
    assert(section  !=  NULL  &&  strlen(section));
    assert(key 
!=  NULL  &&  strlen(key));
    assert(value 
!=  NULL);
    assert(file 
!= NULL  && strlen(key));

    
if (!load_ini_file(file,buf, & file_size))
    {
        sec_s 
=   - 1 ;
    }
    
else
    {
        parse_file(section,key,buf,
& sec_s, & sec_e, & key_s, & key_e, & value_s, & value_e);
    }

    
if - 1   ==  sec_s)
    {
        
        
if ( 0 == file_size)
        {
            sprintf(w_buf
+ file_size, " [%s]\n%s=%s\n " ,section,key,value);
        }
        
else
        {
            
// not find the section, then add the new section at end of the file
            memcpy(w_buf,buf,file_size);
            sprintf(w_buf
+ file_size, " \n[%s]\n%s=%s\n " ,section,key,value);
        }
        
        
    }
    
else   if ( - 1   ==  key_s)
    {
        
// not find the key, then add the new key & value at end of the section
        memcpy(w_buf,buf,sec_e);
        sprintf(w_buf
+ sec_e, " %s=%s\n " ,key,value);
        sprintf(w_buf
+ sec_e + strlen(key) + strlen(value) + 2 ,buf + sec_e, file_size  -  sec_e);
    }
    
else
    {
        
// update value with new value
        memcpy(w_buf,buf,value_s);
        memcpy(w_buf
+ value_s,value, value_len);
        memcpy(w_buf
+ value_s + value_len, buf + value_e, file_size  -  value_e);
    }
    
    
out   =  fopen(file, " w " );
    
if (NULL  ==   out )
    {
        
return   0 ;
    }
    
    
if ( - 1   ==  fputs(w_buf, out ) )
    {
        fclose(
out );
        
return   0 ;
    }

    fclose(
out );
    
    
return   1 ;
}


#ifdef __cplusplus
}; 
// end of extern "C" {
#endif

 

 

#include  < stdio.h >
#include 
" inifile.h "

// main.c
#define  BUF_SIZE 256
int  main()
{
    
const   char   * file  = " myconfig.ini " ;
    
const   char   * section  =   " Db " ;
    
const   char   * key  =   " XX2 " ;
    
    
char  value[BUF_SIZE] = { 0 };
    
    printf(
" test get profile string\n " );

    
if ( ! read_profile_string(section, key, value, BUF_SIZE,"", file))
    {
        
        printf(
" read ini file fail\n " );
    }
    
else
    {
        
int  x  =  read_profile_int(section,key, 0 ,file);
        printf(
" XX2=%d\n " , x);
        printf(
" read: [%s] = [%s]\n " ,key,value);
    }
    
    
if ( ! write_profile_string(section, " XX2 " , " 2writeOK " ,file))
    {
        printf(
" write ini file fail\n " );
    }
    
else
    {
        printf(
" write ini file ok\n " );
    }
    
    
return   0 ;
}


posted on 2006-01-24 16:37 天下无双 阅读(13710) 评论(32)  编辑 收藏 引用 所属分类: C/C++

FeedBack:
# re: Ini文件读写类(ISO-C++)
2006-04-22 12:52 | S
SDFSDF  回复  更多评论
  
# re: C/C++跨平台ini文件读写API
2007-03-08 16:43 | leafy
函数不错,只是有个小bug:
在int write_profile_string里,需要把

if (load_ini_file(file,buf, & file_size))
{
sec_s = - 1 ;
}
else
{
parse_file(section,key,buf, & sec_s, & sec_e, & key_s, & key_e, & value_s, & value_e);
}

改成
if ( ! load_ini_file(file,buf, & file_size))
return 0 ;

if ( ! parse_file(section,key,buf, & sec_s, & sec_e, & key_s, & key_e, & value_s, & value_e))
{
return 0 ; // not find the key
}

  回复  更多评论
  
# re: C/C++跨平台ini文件读写API
2007-03-08 16:47 | leafy
楼主的意思应该是这样(读取不成功,则创建):(少了个非)
if (!load_ini_file(file,buf, & file_size))
{
sec_s = - 1 ;
}
else
{
parse_file(section,key,buf, & sec_s, & sec_e, & key_s, & key_e, & value_s, & value_e);
}
  回复  更多评论
  
# re: C/C++跨平台ini文件读写API
2007-03-08 16:49 | 天下无双
不好意思,我在自己的新版本的代码中改了,网上的版本还没有更新。谢谢指正。  回复  更多评论
  
# re: C/C++跨平台ini文件读写API
2007-03-08 16:54 | 天下无双
对,就是少写了那个!符号。我是这样改的。  回复  更多评论
  
# re: C/C++跨平台ini文件读写API
2007-04-06 16:47 | kate
写的不错
提个问题:
在parse_file中有没有考虑注释行, 比如";this is a comement"
  回复  更多评论
  
# re: C/C++跨平台ini文件读写API
2007-04-07 09:02 | 天下无双
if ( ' ; ' != p[j]) // skip over comment
代码中这句话就是跳过注释的。有这个功能。  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-06-26 11:25 | cxczqfrx

#include < stdio.h >
#include " inifile.h "

// main.c
#define BUF_SIZE 256
int main()
{
const char * file = " myconfig.ini " ;
const char * section = " Db " ;
const char * key = " XX2 " ;

char value[BUF_SIZE] = { 0 };

printf( " test get profile string\n " );

if ( ! read_profile_string(section, key, value, BUF_SIZE, file))
{

printf( " read ini file fail\n " );
}
else
{
int x = read_profile_int(section,key, 0 ,file);
printf( " XX2=%d\n " , x);
printf( " read: [%s] = [%s]\n " ,key,value);
}

if ( ! write_profile_string(section, " XX2 " , " 2writeOK " ,file))
{
printf( " write ini file fail\n " );
}
else
{
printf( " write ini file ok\n " );
}

return 0 ;
}

测试了下,编译提示read_profile_string 缺少参数,改为
if ( ! read_profile_string(section, key, value, BUF_SIZE,NULL, file))
后,能写入文件,但读取失败。  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-06-26 17:04 | 天下无双
读取失败,怎么会呢?看看你的代码。  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-06-26 20:23 | cxczqfrx
#include <stdio.h>
#include "inifile.c"

// main.c
#define BUF_SIZE 256
int main()
{
const char * file = " myconfig.ini " ;
const char * section = " Db " ;
const char * key = " XX2 " ;

char value[BUF_SIZE] = { 0 };

printf( " test get profile string\n " );

if ( ! read_profile_string(section, key, value, BUF_SIZE,NULL, file))
{

printf( " read ini file fail\n " );
}
else
{
int x = read_profile_int(section,key, 0 ,file);
printf( " XX2=%d\n " , x);
printf( " read: [%s] = [%s]\n " ,key,value);
}

if ( ! write_profile_string(section, " XX2 " , " 2writeOK " ,file))
{
printf( " write ini file fail\n " );
}
else
{
printf( " write ini file ok\n " );
}

return 0 ;
}



/**
* @file
* @brief initialization file read and write API
* @author Deng Yangjun
* @date 2007-1-9
* @version 0.1
*/

#ifndef INI_FILE_H_
#define INI_FILE_H_

#ifdef __cplusplus
extern "C"
{
#endif

int read_profile_string( const char *section, const char *key,char *value, int size,const char *default_value, const char *file);
int read_profile_int( const char *section, const char *key,int default_value, const char *file);
int write_profile_string( const char *section, const char *key,const char *value, const char *file);

#ifdef __cplusplus
}; //end of extern "C" {
#endif

#endif //end of INI_FILE_H_

  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-06-26 20:28 | cxczqfrx
/**
* @file
* @brief initialization file read and write API implementation
* @author Deng Yangjun
* @date 2007-1-9
* @version 0.1
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>

#include "inifile.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define MAX_FILE_SIZE 1024*16
#define LEFT_BRACE '['
#define RIGHT_BRACE ']'

static int load_ini_file(const char *file, char *buf,int *file_size)
{
FILE *in = NULL;
int i=0;
*file_size =0;

assert(file !=NULL);
assert(buf !=NULL);

in = fopen(file,"r");
if( NULL == in) {
return 0;
}

buf[i]=fgetc(in);

//load initialization file
while( buf[i]!= (char)EOF) {
i++;
assert( i < MAX_FILE_SIZE); //file too big
buf[i]=fgetc(in);
}

buf[i]='\0';
*file_size = i;

fclose(in);
return 1;
}

static int isnewline(char c)
{
return ('\n' == c || '\r' == c )? 1 : 0;
}
static int isend(char c)
{
return '\0'==c? 1 : 0;
}
static int isleftbarce(char c)
{
return LEFT_BRACE == c? 1 : 0;
}
static int isrightbrace(char c )
{
return RIGHT_BRACE == c? 1 : 0;
}
static int parse_file(const char *section, const char *key, const char *buf,int *sec_s,int *sec_e,
int *key_s,int *key_e, int *value_s, int *value_e)
{
const char *p = buf;
int i=0;

assert(buf!=NULL);
assert(section != NULL && strlen(section));
assert(key != NULL && strlen(key));

*sec_e = *sec_s = *key_e = *key_s = *value_s = *value_e = -1;

while( !isend(p[i]) ) {
//find the section
if( ( 0==i || isnewline(p[i-1]) ) && isleftbarce(p[i]) )
{
int section_start=i+1;

//find the ']'
do {
i++;
} while( !isrightbrace(p[i]) && !isend(p[i]));

if( 0 == strncmp(p+section_start,section, i-section_start)) {
int newline_start=0;

i++;

//Skip over space char after ']'
while(isspace(p[i])) {
i++;
}

//find the section
*sec_s = section_start;
*sec_e = i;

while( ! (isnewline(p[i-1]) && isleftbarce(p[i]))
&& !isend(p[i]) ) {
int j=0;
//get a new line
newline_start = i;

while( !isnewline(p[i]) && !isend(p[i]) ) {
i++;
}

//now i is equal to end of the line
j = newline_start;

if(';' != p[j]) //skip over comment
{
while(j < i && p[j]!='=') {
j++;
if('=' == p[j]) {
if(strncmp(key,p+newline_start,j-newline_start)==0)
{
//find the key ok
*key_s = newline_start;
*key_e = j-1;

*value_s = j+1;
*value_e = i;

return 1;
}
}
}
}

i++;
}
}
}
else
{
i++;
}
}
return 0;
}
  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-06-26 20:29 | cxczqfrx

/**
*@brief read string in initialization file\n
* retrieves a string from the specified section in an initialization file
*@param section [in] name of the section containing the key name
*@param key [in] name of the key pairs to value
*@param value [in] pointer to the buffer that receives the retrieved string
*@param size [in] size of value buffer
*@param default_value [in] defualt value of result
*@param file [in] path of the initialization file
*@return 1 : read success; \n 0 : read fail
*/
int read_profile_string( const char *section, const char *key,char *value,
int size, const char *default_value, const char *file)
{
char buf[MAX_FILE_SIZE]={0};
int file_size;
int sec_s,sec_e,key_s,key_e, value_s, value_e;

//check parameters
assert(section != NULL && strlen(section));
assert(key != NULL && strlen(key));
assert(value != NULL);
assert(size > 0);
assert(file !=NULL &&strlen(key));

if(!load_ini_file(file,buf,&file_size))
{
if(default_value!=NULL)
{
strncpy(value,default_value, size);
}
return 0;
}

if(!parse_file(section,key,buf,&sec_s,&sec_e,&key_s,&key_e,&value_s,&value_e))
{
if(default_value!=NULL)
{
strncpy(value,default_value, size);
}
return 0; //not find the key
}
else
{
int cpcount = value_e -value_s;

if( size-1 < cpcount)
{
cpcount = size-1;
}

memset(value, 0, size);
memcpy(value,buf+value_s, cpcount );
value[cpcount] = '\0';

return 1;
}
}

/**
*@brief int value in initialization file\n
* retrieves int value from the specified section in an initialization file
*@param section [in] name of the section containing the key name
*@param key [in] name of the key pairs to value
*@param default_value [in] defualt value of result
*@param file [in] path of the initialization file
*@return profile int value,if read fail, return default value
*/
int read_profile_int( const char *section, const char *key,int default_value,
const char *file)
{
char value[32] = {0};
if(!read_profile_string(section,key,value, sizeof(value),NULL,file))
{
return default_value;
}
else
{
return atoi(value);
}
}

/**
* @brief write a profile string to a ini file
* @param section [in] name of the section,can't be NULL and empty string
* @param key [in] name of the key pairs to value, can't be NULL and empty string
* @param value [in] profile string value
* @param file [in] path of ini file
* @return 1 : success\n 0 : failure
*/
int write_profile_string(const char *section, const char *key,
const char *value, const char *file)
{
char buf[MAX_FILE_SIZE]={0};
char w_buf[MAX_FILE_SIZE]={0};
int sec_s,sec_e,key_s,key_e, value_s, value_e;
int value_len = (int)strlen(value);
int file_size;
FILE *out;

//check parameters
assert(section != NULL && strlen(section));
assert(key != NULL && strlen(key));
assert(value != NULL);
assert(file !=NULL &&strlen(key));

if(!load_ini_file(file,buf,&file_size))
{
sec_s = -1;
}
else
{
parse_file(section,key,buf,&sec_s,&sec_e,&key_s,&key_e,&value_s,&value_e);
}

if( -1 == sec_s)
{

if(0==file_size)
{
sprintf(w_buf+file_size,"[%s]\n%s=%s\n",section,key,value);
}
else
{
//not find the section, then add the new section at end of the file
memcpy(w_buf,buf,file_size);
sprintf(w_buf+file_size,"\n[%s]\n%s=%s\n",section,key,value);
}
}
else if(-1 == key_s)
{
//not find the key, then add the new key & value at end of the section
memcpy(w_buf,buf,sec_e);
sprintf(w_buf+sec_e,"%s=%s\n",key,value);
sprintf(w_buf+sec_e+strlen(key)+strlen(value)+2,buf+sec_e, file_size - sec_e);
}
else
{
//update value with new value
memcpy(w_buf,buf,value_s);
memcpy(w_buf+value_s,value, value_len);
memcpy(w_buf+value_s+value_len, buf+value_e, file_size - value_e);
}

out = fopen(file,"w");
if(NULL == out)
{
return 0;
}

if(-1 == fputs(w_buf,out) )
{
fclose(out);
return 0;
}

fclose(out);
return 1;
}


#ifdef __cplusplus
}; //end of extern "C" {
#endif


最后的结果文件 myconfig.ini内容:

[ Db ]
XX2 = 2writeOK
XX2 = 2writeOK
XX2 = 2writeOK
XX2 = 2writeOK
XX2 = 2writeOK


看起来好像是运行几次,就写几次新内容,但原来的内容不能读取
使用devcpp编译  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-06-27 10:05 | 天下无双
请从下载链接处下载文件,然后更新原来的工程。  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-07-12 16:03 | 拼命萝卜
请问支持value=后面的值是多行吗?  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-07-14 09:03 | 天下无双
只能是一行。而且在‘=’后面不能有空格。  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-11-08 20:12 | team2vx
大家的调试都没有问题吗?

我的提示
\main.c(16) : error C2198: 'read_profile_string' : too few actual parameters
inifile.cpp
Error executing cl.exe.

main.exe - 1 error(s), 0 warning(s)

是怎么一回事啊?  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-11-08 21:45 | team2vx
同样的问题, 读取失败但是可以 写进去,不知道其他 人都运行成功了吗?  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-11-08 21:49 | 天下无双
测试通过了,没有问题.请放心使用.  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-11-09 07:53 | vxking
不知道 无双现在还在不?
可是我的的确是不能通过,我把代码上传了你能帮我看下吗

http://www.cppblog.com/Files/vxking/inifile.rar

急用,谢谢  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)[未登录]
2007-11-11 16:32 | 天下无双
你的文件调用read_profile_string时候少了一个参数。  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-11-14 17:32 | vxking
你好
现在得问题不是 参数
能通过运行
但是一直读取失败
read ini file fail  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-12-06 11:21 | yuan xiaowei
多谢,已经移植到我的板子上了;不过用的是yaffs2文件系统

yuanxiaoweisz@hotmail.com  回复  更多评论
  
# re: C/C++跨平台ini文件读写API (已更新)
2007-12-07 09:10 | 天下无双
如果要写入的话,肯定是是要把它ini文件放在可写分区的。所以放在yaffs文件系统中没有问题。  回复  更多评论
  
# re: C/C++跨平台ini文件读写API v0.1.0 (已更新)
2007-12-10 09:26 | 天下无双
已经有新版本发布。请大家使用新版本:http://www.cppblog.com/dyj057/archive/2007/12/09/38074.html  回复  更多评论
  
# 函数库有这个功能吗?
2008-05-09 13:03 | wuxunfeng
谢谢楼主的共享。
有个问题想问一下。如果 INI文件中,同一个SECTION中,有几个同样的KEY,那么读取的时候,会读取哪个KEY呢,可以循环读取吗.例:
[SECTION]
key=data
key=data
key=data
key1=data2  回复  更多评论
  
# re: C/C++跨平台ini文件读写API v0.1.0 (已更新)
2008-11-17 16:14 | 小菜
读 写 的 函数怎么调用啊 试了几次 没弄明白。。。。。。。。  回复  更多评论
  
# re: C/C++跨平台ini文件读写API v0.1.0 (已更新)
2008-11-18 16:07 | 楼主
不能循环读写。
@小菜,先引入源文件到工程中,然后在需要的地方引入头文件,再使用函数。  回复  更多评论
  
# re: C/C++跨平台ini文件读写API v0.1.0 (已更新)
2009-01-24 13:01 | 测试测试
性能太差,  回复  更多评论
  
# re: C/C++跨平台ini文件读写API v0.1.0 (已更新)
2009-07-20 15:52 |
经过测试,不能跳过注释  回复  更多评论
  
# re: C/C++跨平台ini文件读写API v0.1.0 (已更新)
2009-11-01 22:28 | kongwch
楼主真是大好人啊,我已经测试通过,不过parse_file函数里面有个bug,如果字段不存在的话会导致内存越界,应该修改为:
}
}
}
}
if (! isend(p[i]) )
{
i ++ ;
}
}
}
}
  回复  更多评论
  
# re: C/C++跨平台ini文件读写API v0.1.0 (已更新)
2010-08-02 19:46 | zhetengfengzi
@路过
可以参考下 http://blog.csdn.net/ddddfw888/archive/2010/08/02/5783165.aspx, 我已经对这个做了相关的修改。  回复  更多评论
  
# re: C/C++跨平台ini文件读写API v0.1.0 (已更新)
2010-10-26 21:20 | 股票计算器
谢谢  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



常用链接

留言簿(15)

随笔分类

随笔档案

相册

我的其它领域Blog

搜索

  •  

积分与排名

  • 积分 - 202567
  • 排名 - 128

最新评论

阅读排行榜

评论排行榜