我尝试使用这个功能复制文件,但输出的文件包含了奇怪的字符。
int File_Copy (char FileSource [], char FileDestination [])
{
int result = -1;
char c [1];
FILE *stream_R = fopen (FileSource, "r");
FILE *stream_W = fopen (FileDestination, "w"); //create and write to file
while ((c [0] = (char) fgetc(stream_R)) != EOF)
{
fprintf (stream_W, c);
}
//close streams
fclose (stream_R);
fclose (stream_W);
return result;
}
我不知道出了什么问题,请帮忙。
fgetc()
返回一个int
类型的值。将其转换为char
会丢失信息。 - pmg