文本文件不能在VC++中正确执行吗?
我在学习文件操作,下面这段代码是将一个文本文件的内容追加到另一个文本文件中去。可以正确编译,可以运行。但得不到正确的运行结果文件,目标文件显示乱码,程序也无法显示。
请大家帮我看看,是什么问题?
程序代码:#include "stdafx.h"
#include "stdlib.h"
#include "string.h"
int main(void)
{
char filetarget[40],fileappend[40];
FILE * ft, * fa;
char ch;
printf("Enter the target file: ");
gets(filetarget);
if ((ft=fopen(filetarget,"a+"))==NULL)
{
printf("Can't open file \"%s\".",filetarget);
exit(1);
}
printf("\nEnter the append file: ");
while(gets(fileappend) && fileappend[0]!='\0')
{
if ((fa=fopen(fileappend,"r"))==NULL)
{
printf("Can't open file \"%s\".",fileappend);
exit(1);
}
while((ch=getc(fa))!=EOF);
putc(ch,ft);
fclose(fa);
printf("\nAppend next file(Empty line to quit): ");
}
puts("\nShow the target file: ");
rewind(ft);
while((ch=getc(ft))!=EOF)
putchar(ch);
fclose(ft);
//end
while(getchar()!='\n');
return 0;
}









