有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列),输出到一个新文件C中。


 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    FILE*fa,*fb,*fc;
    int i,j,k;
    char str[100],str1[100];
    char tem;
    if((fa=fopen("A.txt","r"))==NULL) // A.txt 文件需要存在
    {
        printf("error: cannot open A file!\n");
        exit(0);
    }
    fgets(str,99,fa);
    fclose(fa);
    if((fb=fopen("B.txt","r"))==NULL)  // B.txt 文件需要存在
    {
        printf("error: cannot open B file!\n");
        exit(0);
    }
    fgets(str1,100,fb);
    fclose(fb);
    strcat(str,str1);
    for(i=strlen(str)-1;i>1;i--)
        for(j=0;j<i;j++)
            if(str[j]>str[j+1])
            {
                tem=str[j];
                str[j]=str[j+1];
                str[j+1]=tem;
            }
    
    if((fc=fopen("C.txt","w"))==NULL)  // 合并为 C.txt
    {
        printf("error: cannot open C file!\n");
        exit(0);
    }
    fputs(str,fc);
    fclose(fc);
    system("pause");
    return 0;
}

相关推荐

  1. git 如何合并分支某些文件

    2024-02-20 08:40:01       11 阅读
  2. Python:合并PDF文件一个PDF

    2024-02-20 08:40:01       33 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-20 08:40:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-20 08:40:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-20 08:40:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-20 08:40:01       18 阅读

热门阅读

  1. React 组件状态的使用

    2024-02-20 08:40:01       25 阅读
  2. 第五次作业

    2024-02-20 08:40:01       20 阅读
  3. 常用数据交换格式总结及各自特点

    2024-02-20 08:40:01       23 阅读
  4. c语言指针基础知识点

    2024-02-20 08:40:01       35 阅读
  5. SpringCloud--Ribbon解析

    2024-02-20 08:40:01       31 阅读
  6. spring boot配置Undertow服务器

    2024-02-20 08:40:01       29 阅读
  7. 使用Spring Boot整合Redis实现分布式锁

    2024-02-20 08:40:01       26 阅读
  8. php使用get_browser()函数将移动端和pc端分开

    2024-02-20 08:40:01       32 阅读