#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
FILE*fp,*fp2;
fp=fopen("D:\\C\\file5\\file.txt","r");
fp2=fopen("D:\\C\\file5\\file2.txt","w");
if(fp==NULL)
printf("cannot open file");
if(fp2==NULL)
printf("cannot open file2");
char ch;
while(!feof(fp))
{
ch=fgetc(fp);
putchar(ch);
fputc(ch,fp2);
}
fclose(fp);
fclose(fp2);
return 0;
}
如果while循环里改为:
while(!feof(fp))
{
putchar(fgetc(fp));
fputc(fgetc(fp,fp2);
}
输出内容
file的内容:
abcdefg
hijklmn
opqrstu
vwxyz
一只萌萌小番薯
哈士奇WWW
相关分类