int WritePrivateProfileString(char *section,char *key,char *val,char *filePath)
{
char retval[128];
if(GetPrivateProfileString(section,key,retval,20,filePath)==0)
if(strcmp(val,retval)==0)
return 0;
FILE *file;
char buf1[4096];
char buf2[128];
char *ptr1=NULL;
memset(buf1,'\0',4096);
memset(buf2,'\0',128);
if((file = fopen(filePath,"r"))==NULL)
{
perror("fopen");
exit(-1);
}
while(fread(buf1,sizeof(buf1),1,file) != 0);
fclose(file);
char *ptr[512];
char *tmp=NULL;
int i = 0,j,flag=0;
ptr[i]=strtok(buf1,"\r\n");
while((ptr[++i]=strtok(NULL,"\r\n")) != NULL);
for(j=0;j<i;j++)
{
if(strstr(ptr[j],section)==NULL)
continue;
else
j++;
for(;((j<i) && (*ptr[j] != '['));j++)
{
if(strstr(ptr[j],key) != NULL)
{
strcat(buf2,key);strcat(buf2,"=");
strcat(buf2,val);
ptr[j]=buf2;
}
}
}
#ifdef DEBUG
for(j=0;j < i;j++)
printf("%s\n",ptr[j]);
#endif
if((file = fopen(filePath,"w+"))==NULL)
{
perror("fopen");
exit(-1);
}
for(j=0;j<i;j++)
{
fputs(ptr[j],file);
fputc('\r',file);
fputc('\n',file);
}
fclose(file);
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
linux 读写配置文件 c程序实现
4星 · 超过85%的资源 需积分: 9 318 下载量 16 浏览量
2010-12-28
22:04:47
上传
评论 4
收藏 837B GZ 举报
温馨提示
共2个文件
c:2个
linux下读写配置文件c语言实现 GetPrivateString WritePrivateString
资源推荐
资源详情
资源评论
收起资源包目录
RDWRCONFIG.tar.gz (2个子文件)
reconfig.c 784B
wrconfig.c 1KB
共 2 条
- 1
agame
- 粉丝: 4
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页