标签:
#include <stdio.h>
#include <stdlib.h>
/**
*适用一切文件大小的备份(复制)程序
*@author mohui
*@date 2015/04/10
*/
void main()
{ FILE *sourceFile;
FILE *backupFile;
char source[20],backup[20],ch;
printf("Please enter the name of the source file:\n");
scanf("%s",source);
printf("\n");
printf("Please enter a name for the backup file:\n");
scanf("%s",backup);
printf("\n");
if((sourceFile=fopen(source,"r"))==NULL)
{
printf("$ Error report : Failed to open the source file!!\n");
exit(0);
}
if((backupFile=fopen(backup,"w"))==NULL)
{
printf("$ Error report : Create a new file failed!!\n");
exit(0);
}
do{
ch=fgetc(sourceFile);
fputc(ch,backupFile);
//fputc(ch,stdout); //这行代码用于在运行窗口预览读取的文本内容,为了不必要的增加显示界面占用,不建议写入
}while (!feof(sourceFile));
fclose(sourceFile);
fclose(backupFile);
printf("\n\n.........Backup successfully........\n\n");
}
标签:
原文地址:http://www.cnblogs.com/360-782/p/4415863.html