实现一个渐进优化的 Linux cp 命令

1,第1版 copy

先写个轮廓

selfcp.c  :

#include <stdio.h>

int main() {
    FILE *source, *destination;
    char ch;

    source = fopen("H222.txt", "r");
    if (source == NULL) {
        printf("Error opening source file!\n");
        return 1;
    }

    destination = fopen("H333.txt", "w");
    if (destination == NULL) {
        printf("Error opening destination file!\n");
        return 1;
    }

    while ((ch = fgetc(source)) != EOF) {
        fputc(ch, destination);
    }

    printf("File copied successfully!\n");

    fclose(source);
    fclose(destination);

    return 0;
}

拷贝文本文件:

测试拷贝elf 可执行文件,拷贝结束后,再运行拷贝的结果,会出现 segmentation fault

待查。。。

2,第2版 copy

3,第3版 copy

相关推荐

  1. 【docker】容器优化一行命令换源

    2024-06-16 08:18:01       11 阅读

最近更新

  1. TCP协议是安全的吗?

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

    2024-06-16 08:18:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-16 08:18:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-16 08:18:01       20 阅读

热门阅读

  1. zerotier-one自建根服务器方法一

    2024-06-16 08:18:01       8 阅读
  2. MyBatis 参数传递详解

    2024-06-16 08:18:01       6 阅读
  3. Python闯LeetCode--第3题:无重复字符的最长子串

    2024-06-16 08:18:01       9 阅读
  4. React如何配置路由

    2024-06-16 08:18:01       6 阅读
  5. MAC 下搭建LVGL仿真器

    2024-06-16 08:18:01       7 阅读
  6. 科普计算机的相关知识【下】

    2024-06-16 08:18:01       8 阅读
  7. 车载网络安全指南 生产、运行和服务阶段(九)

    2024-06-16 08:18:01       11 阅读
  8. 学习笔记——交通安全分析05

    2024-06-16 08:18:01       9 阅读
  9. axios进阶——取消已经发出去的请求

    2024-06-16 08:18:01       8 阅读
  10. 前端HTML相关知识

    2024-06-16 08:18:01       10 阅读
  11. 大数据—什么是大数据?

    2024-06-16 08:18:01       9 阅读