摘要:本文主要向大家介绍了C/C++知识点之C语言实现文件的读写复制(书本改进源码版),通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。
本文主要向大家介绍了C/C++知识点之C语言实现文件的读写复制(书本改进源码版),通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。
#include
#include
/**
*适用一切文件大小的备份(复制)程序
*@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");
}
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标编程语言C/C+频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号