使用C语言实现对ini文件的访问

[复制链接]
2421|1
 楼主| 四叶草 发表于 2007-11-3 15:21 | 显示全部楼层 |阅读模式
请问怎样使用C语言实现对ini文件的访问?是用那个fopen()函数吗?有那个会的请把比较完整的代码或方法告诉我吧,谢谢。
微风 发表于 2007-11-3 18:08 | 显示全部楼层

像这样

#include&nbsp;&ltstdio.h&gt<br />#include&nbsp;&ltstdlib.h&gt<br /><br />void&nbsp;main(void)<br />{<br />FILE&nbsp;*file;<br />FILE&nbsp;*log;&nbsp;<br />double&nbsp;tmp;<br />if&nbsp;((log&nbsp;=&nbsp;fopen(&quot;log.txt&quot;,&quot;w&quot;))==NULL)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(1);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />if&nbsp;((file&nbsp;=&nbsp;fopen(&quot;test.ini&quot;,&quot;r&quot;))==NULL)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(log,&quot;
Cannot&nbsp;open&nbsp;input&nbsp;file!
&quot;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(1);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />fscanf(file,&nbsp;&quot;%lf&quot;,&tmp);<br />fprintf(log,&quot;data&nbsp;is&nbsp;:%lf
&quot;,tmp);<br />fclose(file);<br />fclose(log);<br />}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

71

主题

109

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部