我的INI文件是这样的
[111]
PATH=c:\pocimageproc\inputdcmfile
[222]
PATH=C:\pocimageproc\outputdcmfile
[333]
EXT=.dcm
[444]
TIMEOUTVAL=10000
[LUT_FILE_PATH]
PATH=C:\pocimageproc\lutfile
[555]
chest=LL.ini
admon=LL.ini
sKull=LL.ini
else=LL.ini
[666] 
GRPNO=0018
ELEMENT=0015怎么才能遍历整个INI文件把所有中括号里的值都取到?

解决方案 »

  1.   

    [xxx]不是一个标识符吗?相当于个索引
    用来读取【】下的其他值,难道不是吗?其他我不知道
      

  2.   

    你可以用一下两个方法组合来实现
    GetPrivateProfileSectionNames:获取所有section name 存放在一个szBuffer中,section name用‘\0’来区分的
    GetPrivateProfileSection:获取特定section name下的所有节点以及节点的值 存放在szBuffer中,格式是
    chest=LL.ini'\0'admon=LL.ini'\0'sKull=LL.ini'\0'else=LL.ini
    这两个方法都可以通过返回值来获得 szBuffer中有多少个字符。包括'\0'
      

  3.   

    API提供的INI文件操作函数,没有遍历的,因为总是知道了节和值名才需要存取。看你的意思不需要通过API的ini函数来操作,自己当作一个普通文件读取解析好了。
      

  4.   


    char *name = "test.ini";
    FILE *file = fopen(name, "r");
    char buf[256];
    int len;
    while(len = fscanf(file, "%s", buf) != EOF)
    {
    if (buf[0] == '[' && buf[len - 1] == ']')
    {
    printf("%s\n", buf);
    }
    }
    fclose(file);
      

  5.   

    我在尝试用tinyXML做配置文件现在修改节点有点问题, 等试好了我就发到我的博客里
      

  6.   

    用GetPrivateProfileInt读取数值
    用GetPrivateProfileString读取字符串
      

  7.   

    参考:
    http://www.joyvc.cn/GUI_and_Window/GUIAndWindwMain00067.html
    http://www.joyvc.cn/GUI_and_Window/GUIAndWindwMain00053.html
      

  8.   

    char * pSectionName; 
    int i;      
    int j=0;     
    int count=0;     for(i=0;i<2048;i++,j++)
    {
    if(strSectionNames[0]=='\0')
    break;      
    if(strSectionNames[i]=='\0')
    {
    pSectionName=&strSectionNames[i-j];
    j=-1;        

    //pSectionName里面就是你要的项名

    if(strSectionNames[i+1]==0)
    {
    break;
    }
    }   
    }