• 磁盘读写,合并排序字符串


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

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    #include <iostream>
    using namespace std;

    int main(void)
    {
    FILE *fp;
    char strA[100], strB[100];
    if((fp = fopen("a.txt","w")) == NULL)
    {
    printf("error, create a.txt failed");
    exit(0);
    }
    fprintf(fp,"qwertyuiop");
    fclose(fp);
    if((fp = fopen("a.txt","r")) == NULL)
    {
    printf("error, read a.txt failed");
    exit(0);
    }
    fgets(strA, 100, fp);
    fclose(fp);

    if((fp = fopen("b.txt","w")) == NULL)
    {
    printf("error, create b.txt failed");
    exit(0);
    }
    fprintf(fp,"asdfghj");
    fclose(fp);
    if((fp = fopen("b.txt","r")) == NULL)
    {
    printf("error, read b.txt failed");
    exit(0);
    }
    fgets(strB, 100, fp);
    fclose(fp);

    printf("strlenA is %d , strlenB is %d ", strlen(strA), strlen(strB));
    strcat(strA,strB);
    char tmp;
    printf("strlenA is %d , strlenB is %d ", strlen(strA), strlen(strB));
    for(int i=(strlen(strA)-1); i>0; i--)
    {
    for(int j=0; j<i; j++)
    {
    if(strA[j] > strA[i])
    {
    tmp = strA[i];
    strA[i] = strA[j];
    strA[j] = tmp;
    }
    }
    }
    if((fp = fopen("c.txt","w")) == NULL)
    {
    printf("error, create c.txt failed");
    exit(0);
    }
    fputs(strA, fp);
    fclose(fp);
    return 0;
    }

  • 相关阅读:
    H5中获取图片中的主色调
    vue provide/inject响应式
    微信小程序入坑之路
    H5入坑之路
    uni-app状态栏相关问题
    uni-app使用iconfont相关
    uni-app入坑之路
    uni-app自定义导航栏(搜索框和按钮)
    浅析浏览器的渲染过程
    SAP ABAP MB51新增栏位字段
  • 原文地址:https://www.cnblogs.com/embeddedking/p/9694040.html
Copyright © 2020-2023  润新知