风花雪月 发表于 2006-6-16 20:45

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

#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;<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')<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>上面程序中,紅字部分起到什麼作用?

zhuwy16 发表于 2006-6-19 20:13

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

<STRONG><FONT color=#0000ff size=5>fprintf(文件指针,格式字符串,输出表列);<BR><BR>这句话的意思就是在 fp对应的文件里写入字符串。</FONT></STRONG>
页: [1]
查看完整版本: [讨论]一行代码的具体含义(+1-3分)