1. 程式人生 > >Linux 上標準c複製檔案

Linux 上標準c複製檔案

#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; }

這裡寫圖片描述