Linux 上标准c复制文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/minwenping/article/details/78847004
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
int _tmain(int argc, _TCHAR* argv[])
{
    char *path = "C:\\Users\\Administrator\\Desktop\\original.PNG";
    char *newpath = "C:\\Users\\Administrator\\Desktop\\copy.PNG";
    //标准c复制文件
    FILE *file = fopen(path, "rb");
    FILE *copy = fopen(newpath,"wb");
    if (file == NULL){
        printf("%s\n","文件打开失败!。。。");
        return -1;
    }

    if (copy==NULL)
    {
        printf("%s\n", "文件打开失败");
        return -1;
    }

    int buffer[50] = {0};
    int temp = 0;
    while ((temp=fread(buffer, sizeof(int), 50, file))>0)
    {
        printf("读取个数:%d\n",temp);
        fwrite(buffer, sizeof(int), temp, copy);
    }
    printf("读取完成");

    int clsoe1=fclose(file);
    int close2=fclose(copy);
    printf("关闭结果:%d%d\n", clsoe1, close2);
    return 0;
}

这里写图片描述

猜你喜欢

转载自blog.csdn.net/minwenping/article/details/78847004