我的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文件把所有中括号里的值都取到?
[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文件把所有中括号里的值都取到?
用来读取【】下的其他值,难道不是吗?其他我不知道
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'
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);
用GetPrivateProfileString读取字符串
http://www.joyvc.cn/GUI_and_Window/GUIAndWindwMain00067.html
http://www.joyvc.cn/GUI_and_Window/GUIAndWindwMain00053.html
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;
}
}
}