读取文件内容并写入另一个文件。
/**
* @file : copy.c
* @author : 羽墨志(https://yumozhi.com/)
* @since : 2019年8月5日18:13:27
* @description : 文件复制
*/
#include<stdio.h>
/**
* @function : main
* @author : 羽墨志(https://yumozhi.com/)
* @since : 2019年8月5日18:15:41
* @description : 文件复制
* @parameter : none
* @return : 0
*/
int main(int argc, char * argv[])
{
char ch;
FILE *in;
FILE *out;
printf("Usage: copy filename1 filename2\n");
if(argc != 3)
{
printf("Error Usage ... \n");
return 0;
}
//以只读方式打开文件
if((in=fopen(argv[1],"r")) == NULL)
{
printf("Open file %s failed ... \n", argv[1]);
return 0;
}
//以读写方式打开文件
if((out=fopen(argv[2],"w")) == NULL)
{
printf("Open file %s failed ... \n", argv[2]);
return 0;
}
//逐个读取文件中的字符并输出
while((ch=fgetc(in))!=EOF)
{
fputc(ch,out);
}
fclose(in);
fclose(out);
return 0;
}