文件操作练习一:文件复制

/*把一个磁盘文件中的信息复制到另一个磁盘文件中*/
#include "stdio.h"
#include "stdlib.h"
void main()
{
	FILE *fp1, *fp2;
	char ch;

	if((fp1 = fopen("C:\\file_1.txt","r")) ==NULL)	//首先确保C:\\file_1.txt文件存在
	{
		printf("cannot open C:\\file_2.txt file!\n");
		exit(1);
	}

	if((fp2 = fopen("D:\\file_2.txt","w+")) ==NULL)
	{
		printf("cannot open D:\\file_2.txt file!\n");
		exit(1);
	}

	while(!feof(fp1))
	{
		ch = getc(fp1);
		fputc(ch, fp2);
	}
	printf("文件复制成功!请查看D:\\file_2.txt文件\n");

	fclose(fp1);
	fclose(fp2);

}

你可能感兴趣的:(文件操作练习一:文件复制)