#include<stdio.h>
#include<assert.h>
//文件拷贝
//将文件src拷贝到des
void FileCopy(const char *des,const char *src)
{
FILE *fr = fopen(src,“rb”);
FILE *fw = fopen(des,“wb”);
assert(fr!=NULL && fw !=NULL);
char buf[1024];//1k
int len;
while((len=fread(buf,sizeof(char),1024,fr)) > 0)
{
fwrite(buf,sizeof(char),len,fw);
}
fclose(fr);
fclose(fw);
}
int main()
{
char *path1 = "源.cpp";
char *path2 = "1.cpp";
FileCopy(path2,path1);
return 0;
}
void FileCopy1(const char *des,const char *src)//buf太小,效率差,文件IO很耗时
{
FILE *fr = fopen(src,“rb”);
FILE *fw = fopen(des,“wb”);
assert(fr!=NULL && fw !=NULL);
char tmp;//buf太小,效率差,文件IO很耗时
while(fread(&tmp,sizeof(char),1,fr) > 0)
{
fwrite(&tmp,sizeof(char),1,fw);
}
fclose(fr);
fclose(fw);
}
int main()
{
char *path1 = "源.cpp";
char *path2 = "1.cpp";
FileCopy1(path2,path1);
return 0;
}