gpt4 book ai didi

c - C语言如何将图像复制到目录

转载 作者:太空宇宙 更新时间:2023-11-04 03:49:44 27 4
gpt4 key购买 nike

我正在尝试使用文件打开和写入文件方法复制图像文件,但无法实现图像...所以请帮我解决代码以及所需的头文件。

   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);

瓦尔特

关于c - C语言如何将图像复制到目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21713777/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com