声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2224|回复: 1

[C/C++] [讨论]一行代码的具体含义(+1-3分)

[复制链接]
发表于 2006-6-16 20:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
#include &lt;stdio.h&gt;<BR>#include &lt;stdlib.h&gt;<BR>#define MAX 40<BR>int main (void)<BR>{<BR>    FILE *fp;<BR>    char words[MAX];<BR><BR>    if((fp = fopen("words","a+")) == NULL)<BR>    {<BR>       fprintf(stdout,"Can,t open \"words\"file.\n");<BR>       exit(1);<BR>    }<BR>    puts("Enter words to add to the file:press the Enter");<BR>    puts("key at the beginning of a line to terminate.");<BR>    while(gets(words) != NULL &amp;&amp; words[0] != '\0')<BR>        <FONT color=#ff0000> fprintf(fp,"%s ",words);</FONT>   <BR>   puts("File contents: ");<BR>    rewind(fp);<BR>    while(fscanf(fp,"%s",words) == 1)<BR>         puts(words);<BR>         getch();<BR>    if(fclose(fp) != 0)<BR>       fprintf(stderr,"Error closing file\n");<BR>    return 0;<BR>}<BR>上面程序中,紅字部分起到什麼作用?
回复
分享到:

使用道具 举报

发表于 2006-6-19 20:13 | 显示全部楼层

回复:(风花雪月)[讨论]一行代码的具体含义(+1-3分...

<STRONG><FONT color=#0000ff size=5>fprintf(文件指针,格式字符串,输出表列);<BR><BR>这句话的意思就是在 fp对应的文件里写入字符串。</FONT></STRONG>
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-11 13:48 , Processed in 0.056089 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表