代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#define SIZE 1024*1024*8
int main(int argc, const char * argv[]) {
if(argc < 3){
printf("缺少参数\n");
return -1;
}
for (int i=0; i< argc; i++) {
printf("%s\n",argv[i]);
}
FILE* fp1 = fopen(argv[1], "rb");
FILE* fp2 = fopen(argv[2], "w");
unsigned long count = 0;
struct stat st;
stat(argv[1], &st);
char* tmp = NULL;
int size = 0;
if(st.st_size > SIZE){
tmp = (char*)malloc(sizeof(char)* SIZE);
size = SIZE;
}else{
tmp = (char*)malloc(sizeof(st.st_size)+ 10);
size = st.st_size + 10;
}
while (!feof(fp1)) {
count = fread(tmp, sizeof(char), size, fp1);
fwrite(tmp, sizeof(char), count, fp2);
}
printf("文件复制完成\n");
fclose(fp1);
fclose(fp2);
return 0;
}