如何使用C语言实现copy拷贝的功能
程序员文章站
2022-07-15 09:57:29
...
如何使用C语言实现copy拷贝的功能
注:本程序实现的是两个文件在同一目录下
#include
int main(void){
char buf[100] = {};
int size = 0;
FILE *p_file = fopen("b.out","rb");
FILE *p_dest = fopen("c.out","wb");
if(!p_file){
return 0;
}
p_dest = fopen("c.out","wb");
if(!p_file){
fclose(p_file);
p_file = NULL;
return 0;
}
while(size = fread(buf,sizeof(char),100,p_file)){
fwrite(buf,sizeof(char),size,p_dest);
}
fclose(p_dest);
p_dest = NULL;
fclose(p_file);
p_file = NULL;
return 0;
}