文件的读写操作

windows vc++6.0下通过
功能:输入一些字符给txt1,以#结尾,然后txt2中也会写入这些字符。
两个文件在.c文件所在文件夹。



/////////////////////////////////////////////////文件的读写操作//////////////////////////////////////////////////////
#include<stdio.h>

main()
{
char c;
FILE *fp1,*fp2;
if((fp1=fopen("t1.txt","w+"))==NULL)
{
    printf("Cannot open t1.txt!\n");exit(1);
}
if((fp2=fopen("t2.txt","w+"))==NULL)
{
    printf("Cannot open t2.txt!\n");exit(1);
}
while((c=getchar())!='#')
fputc(c,fp1);
rewind(fp1);
while((c=fgetc(fp1))!=EOF)
fputc(c,fp2);
rewind(fp2);
while((c=fgetc(fp2))!=EOF)
putchar(c);
fclose(fp1);
fclose(fp2);
}

这里写图片描述

这里写图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42828324/article/details/81288336
今日推荐