zoukankan      html  css  js  c++  java
  • 复制一个文件

    #include <stdio.h>
    #include <string.h>
    #include <errno.h>
    
    #define BUF_SIZE   32
    
    int main(int argc, char  *argv[])
    {
        if (argc != 3)
        {
            printf("Uage: ./copy dest src");
            return -1;
        }
        
        char *src = argv[1];
        char *dest = argv[2]; 
    
    
        FILE* file1 =  fopen(dest, "r");
        FILE* file2 =  fopen(src, "w+");
    
    
        char file1_buf[BUF_SIZE];
    
        while(1)
        {
            int ret = fread(file1_buf, sizeof(char), BUF_SIZE, file1);
            ret = fwrite(file1_buf, 1, ret, file2);
            if (ret < BUF_SIZE)
            {
                printf("write %s %s
    " , dest, strerror(errno));
                return 0;
            }  
        }
        fclose(file1);
        fclose(file2);
    
        return 0;
    }
    
  • 相关阅读:
    软硬链接
    查看文件内容
    cp+mv
    cd+rm+pwd
    ls+tree
    绝对路径和相对路径
    Linux目录结构
    修改hostname
    java. util. concurrent. atomic
    git
  • 原文地址:https://www.cnblogs.com/ding-ding-light/p/14152206.html
Copyright © 2011-2022 走看看