zoukankan      html  css  js  c++  java
  • 仿Linux中的cp操作

    分别用系统调用和标准库函数两种方式编写一个程序对文件逐个字符进行拷贝,其中源文件名为"./file.in"是一个二进制文件,目标文件名是"./file.out",目标文件的权限为文件属性为:可读可写

     1 /*
     2  ============================================================================
     3  Name        : test_cp.c
     4  Author      : 
     5  Version     :
     6  Copyright   : Your copyright notice
     7  Description : Hello World in C, Ansi-style
     8  ============================================================================
     9  */
    10 
    11 #include <stdio.h>
    12 #include <stdlib.h>
    13 
    14 int main(int argc, char * argv[]) {
    15     FILE * source, *des;
    16     char buffer[BUFSIZ + 1];//BUFSIZ=8014,是系统已定义的
    17 //这里可以让这个程序更通用,使用main函数来传值
    18 //    if (argc < 3) {
    19 //        printf("please input source file path and destination file path\n");
    20 //        exit(1);
    21 //    }
    22 
    23     source = fopen("./file.in", "r");
    24     des = fopen("./file.out", "w");
    25 
    26     if (source == NULL || des == NULL) {//判断当前目录下是否有文件
    27         perror("open failed");
    28         exit(1);
    29     }
    30     printf("开始将目标文件复制到目的文件\n");
    31     while (fgets(buffer, BUFSIZ, source) != NULL) {    //每次读取一行,将source的内容复制到des中
    32         fputs(buffer, des);
    33     }
    34     exit(0);
    35 }
  • 相关阅读:
    【VUE3.0体验】关于路由的一些坑
    TensorFlow中的卷积函数
    TensorFlow源码安装
    ubuntu远程桌面
    TensorFlow图像处理API
    C程序员眼里的Python
    深度剖析HashMap的数据存储实现原理(看完必懂篇)
    golang 互斥锁和读写锁
    golang goroutine的调度
    golang channel的使用以及调度原理
  • 原文地址:https://www.cnblogs.com/kissazi2/p/2868274.html
Copyright © 2011-2022 走看看