写一个函数实现文件拷贝功能

 1 #include<stdio.h>
 2 
 3 int main(int argc,char *argv[])
 4 {
 5     if(argc<3){
 6         printf("参数输入错误\n");
 7         return 0;
 8     }
 9 
10     FILE *p_src = fopen(argv[1],"rb");
11     if(!p_src){
12         printf("读取文件失败\n");
13         return 0;
14     }
15 
16     FILE *p_dst = fopen(argv[2],"wb");
17     if(!p_dst){
18         printf("写入文件失败\n", );
19         fclose(p_src);
20         p_src = NULL;
21         return 0;
22     }
23 
24     int size = 0;
25     while(1){
26         size = fread(buf,sizeof(char),100,p_src);
27         if(!size)
28             break;
29         fwrite(buf,sizeof(char),size,p_dst);
30     }
31     
32     fclose(p_dst);
33     p_dst = NULL;
34     fclose(p_src);
35     p_src = NULL;
36 
37 }

猜你喜欢

转载自www.cnblogs.com/ll-10/p/9687092.html