这里写代码片
/*将一个磁盘文件中的信息复制到另一个磁盘文件*/
# include<stdio.h>
int main()
{
FILE*fin,*fout;
char infile[10]="awe.txt",outfile[10]="awea.docx";
char ch;
//printf("Enter the infile name:\n");
//scanf("%s",&infile);
//printf("Enter the outfile name:\n");
//scanf("%s",&outfile);
if((fin=fopen(infile,"r"))==NULL)
{
printf("Cannot open infile\n");
return 0;
}
if((fout=fopen(outfile,"w"))==NULL)
{
printf("Cannot open outfile\n");
return 0;
}
while(ch!=EOF)
//while(!feof(fin))
{
//putchar(ch1);
ch=fgetc(fin);
fputc(ch,fout);
}
fclose(fin);
fclose(fout);
}
awe.txt中的内容为asd pwe,如下图:
运行代码后,awea.docx文件中的内容变为asd pwe,成功将awe.txt中的内容复制到其中