文件复制程序 file_copy.c
2013-10-14 10:22
405 查看
#include<stdio.h> #include<stdlib.h> #define BUFFER_SIZE 1024 int main(int argc,char ** argv) { FILE *fileForm,*fileTo; char buffer[BUFFER_SIZE]={0}; int length=0; /*检查输入命令格式是否正确*/ if(argc!=3) { printf("Usage:%s fileForm fileTo\n",argv[0]); exit(0); } /*打开源文件*/ fileForm=fopen(argv[1],"rb+"); if(fileForm==NULL) { printf("Open File %s Failed\n",argv[1]); exit(0); } /*打开或创建目标文件*/ fileTo=fopen(argv[2],"wb+"); if(fileTo==NULL) { printf("Open File %s Failed\n",argv[2]); exit(0); } /*复制文件内容*/ while((length=fread(buffer,1,BUFFER_SIZE,fileForm))>0) { fwrite(buffer,1,length,fileTo); } /*关闭文件*/ fclose(fileForm); fclose(fileTo); return 0; }
编译源程序并生成可执行程序file_copy,然后执行程序,将hello.c复制成zhs.c,则编译和运行命令如下:
# gcc file_copy.c -o file_copy # ./file_copy hello.c zhs.c
相关文章推荐
- 使用 SqlBulkCopy 大量复制文字文件之 C# 程序代码
- 使用 SqlBulkCopy 大量复制文字文件之 C# 程序代码
- asp.net 文件复制或删除用相对路径,File.Copy中用相对路径,巧用相对路径复制文件
- 利用FileChannel复制文件 Copy one File to Another【三种方法】
- 4 Ways to Copy File in Java -- Java 复制文件的方法
- java移动/复制文件 copy/move file
- java移动/复制文件 copy/move file
- PHP文件操作,多行句子的读取,file()函数,file_get_contents()函数,file_put_contents()函数,is_file,统计网站pv (访问量),文件的复制 copy
- 利用spring中的FileCopyUtils.copy()复制文件
- ubuntu 复制文件到xp (How i can copy file from server(OS:ubuntu 10.04) to my PC
- IO File.copy 实现文件的复制
- 利用spring中的FileCopyUtils.copy()复制文件
- 利用spring中的FileCopyUtils.copy()复制文件
- Java: File copy in Java – Benchmark(Java文件复制)
- 设计一程序(Copy.java),可以实现文件的复制操作
- 以byte[]类型复制文件 Copy a file with read(byte[] data) and write(byte[] data)
- 复制文件/文件夹以及子文件夹下的文件; Copy file/folder including subfolder/files
- 两台硬件和软件配置完全相同的机器A和B,现在要用系统自带的Copy功能把A上的一个文件,复制到B上。在哪台机器上执行程序,效率更高?
- asp.net 文件复制或删除用相对路径,File.Copy中用相对路径,巧用相对路径复制文件
- C#FileStream复制大文件