【问题标题】:How to copy a image to a Directory in C languageC语言如何将图像复制到目录中
【发布时间】:2014-03-09 22:37:51
【问题描述】:

我试图使用文件打开和写入文件方法复制图像文件,但启用以实现图像...所以请帮助我提供代码以及所需的头文件。

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

我试过这个....

【问题讨论】:

  • 那么你的问题是什么?
  • 你应该开始代码,然后我们看看它。
  • 你需要<stdio.h>;你可以使用fread()fwrite();你将使用fopen();您可能会使用b 作为公开通话中的标志之一。
  • 请以正确格式的格式将您的代码编辑到问题中(无制表符;缩进)。通过选择格式化代码并按编辑框上方的{}按钮转换为代码。
  • 使用int ch和文件模式“rb”、“wb”。

标签: c image directory copy


【解决方案1】:

试试:

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

变态

【讨论】:

    猜你喜欢
    • 2017-03-14
    • 2021-04-06
    • 2017-03-26
    • 1970-01-01
    • 1970-01-01
    • 2016-11-21
    • 2023-03-09
    • 2017-11-24
    • 2020-12-14
    相关资源
    最近更新 更多