编一个程序,将名为“d: \f1.txt”的文本文件复制在同一目录下,文件名改为“f2.txt”

来源:百度知道 编辑:UC知道 时间:2024/06/17 01:48:01

使用记事本输入
copy D:\f1.txt D:\f2.txt
保存成后缀为bat的文件,双击执行就行了

#include<stdio.h>
#include<stdlib.h>
void main()
{
char *srcFile="d:\\f1.txt"; //源文件目录
char *destFile="d:\\f2.txt"; //目标文件目录
char ch;
FILE *sfp,*dfp;
if ((sfp=fopen(srcFile,"r"))==NULL)
{
printf("源文件打开失败:%s",*srcFile);
exit(1);
}
if ((dfp=fopen(destFile,"w"))==NULL)
{
printf("目标文件打开失败:"+*destFile);
exit(1);
}
while ((ch=getc(sfp))!=EOF)
putc(ch,dfp);
fclose(sfp);
fclose(dfp);
}