新手求教一个关于文本内容复制的问题
#include"stdio.h"#include"ctype.h"
#include"stdlib.h"
main(void)
{
int a=0,b;
FILE *f1,*f2;
char f1name[20],f2name[20];
char str[30]="this is a test string";
/*在已存在的test.txt中输入数组str[]*/
scanf("%s",&f1name);
if((f1=fopen(f1name,"rb+"))==NULL)
printf("failed to open the file1\n");
else
for(a;a<30;a++)
fputc(str[a],f1);
fclose(f1); /*??*/
/*将test1.txt中内容复制到test2.txt*/
scanf("%s",&f2name);
if((f2=fopen(f2name,"w+"))==NULL)
printf("failed to create a file\n");
else
f1=fopen(f1name,"r"); /*??*/
while((b=getc(f1))!=EOF)
fputc(b,f2);
system("pause");
}
弄不明白为什么少了??的步骤 test2.txt就是空白文件