[英]How to copy a image to a Directory in C language
我试图使用文件打开和写入文件方法来复制图像文件,但是启用了实现图像的功能。因此,请帮助我提供代码以及所需的头文件。
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);
瓦尔特
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.