Ini 文件使用与读取

/*
Config.ini
====================================================
[VirtualPrintconfig]
path=c:\windows\system32
number=100

*/
int main(int argc, char* argv[])
{
// printf(“Hello World!\n”);

char path[MAX_PATH]=”D:\\config.ini”;
char Buffer[500];
int num;
memset(Buffer,0,sizeof(Buffer));
//读取字符
GetPrivateProfileString(“VirtualPrintconfig”, //应用程序名也就是在ini文件中[ ]
“path”, //读取指定键
NULL,
Buffer, //保存
500, //Buffer大小
path); //ini所在路径
num=GetPrivateProfileInt(“VirtualPrintconfig”,”number”,NULL,path); //读取数字

printf(“%s\n”,Buffer);
printf(“%d\n”,num);
strcpy(Buffer,”c:\\windows\\system32″);
num=1000;
char strnum[10];

WritePrivateProfileString(“VirtualPrintconfig”,”path”,Buffer,path); //写入配置文件
//写入数值
sprintf(strnum,”%d”,num);
WritePrivateProfileString(“VirtualPrintconfig”,”number”,strnum,path);
return 0;
}

随机日志

发表评论

0 评论.

Leave a Reply



[ Ctrl + Enter ]

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

CNXCT小组的博客 is Stephen Fry proof thanks to caching by WP Super Cache