<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://www.gentoo-zh.org/extern.php?action=feed&amp;tid=408&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Gentoo中文社区 / C 练习实例99]]></title>
		<link>https://www.gentoo-zh.org/viewtopic.php?id=408</link>
		<description><![CDATA[C 练习实例99 最近发表的帖子。]]></description>
		<lastBuildDate>Mon, 29 Aug 2022 11:58:16 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[C 练习实例99]]></title>
			<link>https://www.gentoo-zh.org/viewtopic.php?pid=414#p414</link>
			<description><![CDATA[<p>题目：有两个磁盘文件A和B,各存放一行字母，要求把这两个文件中的信息合并（按字母顺序排列），输出到一个新文件C中。</p><p>程序分析：你需要先创建 A.txt 与 B.txt。</p><p>A.txt文件内容：</p><p>123</p><p>B.txt文件内容：</p><p>456</p><p>程序源代码：</p><div class="codebox"><pre class="vscroll"><code>#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt;
#include&lt;string.h&gt;
int main()
{
    FILE*fa,*fb,*fc;
    int i,j,k;
    char str[100],str1[100];
    char tem;
    if((fa=fopen(&quot;A.txt&quot;,&quot;r&quot;))==NULL) // A.txt 文件需要存在
    {
        printf(&quot;error: cannot open A file!\n&quot;);
        exit(0);
    }
    fgets(str,99,fa);
    fclose(fa);
    if((fb=fopen(&quot;B.txt&quot;,&quot;r&quot;))==NULL)  // B.txt 文件需要存在
    {
        printf(&quot;error: cannot open B file!\n&quot;);
        exit(0);
    }
    fgets(str1,100,fb);
    fclose(fb);
    strcat(str,str1);
    for(i=strlen(str)-1;i&gt;1;i--)
        for(j=0;j&lt;i;j++)
            if(str[j]&gt;str[j+1])
            {
                tem=str[j];
                str[j]=str[j+1];
                str[j+1]=tem;
            }
    
    if((fc=fopen(&quot;C.txt&quot;,&quot;w&quot;))==NULL)  // 合并为 C.txt
    {
        printf(&quot;error: cannot open C file!\n&quot;);
        exit(0);
    }
    fputs(str,fc);
    fclose(fc);
    system(&quot;pause&quot;);
    return 0;
}</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (batsom)]]></author>
			<pubDate>Mon, 29 Aug 2022 11:58:16 +0000</pubDate>
			<guid>https://www.gentoo-zh.org/viewtopic.php?pid=414#p414</guid>
		</item>
	</channel>
</rss>
