Linux 上標準c複製檔案
阿新 • • 發佈:2018-11-05
#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;
}