我正在尝试使用文件打开和写入文件方法复制图像文件,但无法实现图像...所以请帮我解决代码以及所需的头文件。
char ch, source_file[20], target_file[20];
FILE *source, *target;
source = fopen("Source", "r");
if( source == NULL )
{
printf("Press any key to exit...\n");
}
target = fopen("Destination", "w");
if( target == NULL )
{
fclose(source);
}
while( ( ch = fgetc(source) ) != EOF )
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
我试过这个....
尝试:
FILE *source, *target;
int i;
source = fopen("Source", "rb");
if( source == NULL ) { printf("Press any key to exit...\n");} //exit(EXIT_FAILURE);
fseek(source, 0, SEEK_END);
int length = ftell(source);
fseek(source, 0, SEEK_SET);
target = fopen("Destination", "wb");
if( target == NULL ) { fclose(source); } //exit(EXIT_FAILURE);
for(i = 0; i < length; i++){
fputc(fgetc(source), target);
}
printf("File copied successfully.\n");
fclose(source);
fclose(target);
瓦尔特
我是一名优秀的程序员,十分优秀!