鱼C论坛

 找回密码
 立即注册
查看: 3031|回复: 5

为什么我用图片文件合成,每次都说我图片打不开呢?

[复制链接]
发表于 2014-2-14 11:39:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<stdio.h>
#include<stdlib.h>
void main()
{
        FILE *picture,*file,*finish;
        char picture_name[20],file_name[20],finish_name[20];
        char ch;

        printf("请输入需要合成的图片和文件的名称:  \n");
        printf("图片:  ");
        scanf("%s",picture_name);
        printf("文件:  ");
        scanf("%s",file_name);
        printf("生成的文件名称:  ");
        scanf("%s",finish_name);

        if(!(picture=fopen(picture_name,"r")))
        {
                printf("Cannot open the picture %s !",picture_name);
                return;
        }
        if(!(file=fopen(file_name,"r")))
        {
                printf("Cannot open the file %s !",file_name);
                return;
        }
        if(!(finish = fopen(finish_name,"w")))
        {
                printf("Cannot open the finish %s !",finish_name);
                return;
        }

        while(!(feof(picture)))
        {
                ch = fgetc(picture);
                fputc(ch,finish);
        }
        fclose(picture);
        while(!(feof(file)))
        {
                ch = fgetc(file);
                fputc(ch,finish);               
        }
        fclose(file);
        fclose(finish);

        system("pause");
}


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2014-2-14 13:10:49 | 显示全部楼层
QQ图片20140214130921.jpg QQ图片20140214130819.jpg 这是运行的报错,和我要合成的图片和文件,我是初学者求高手教下,万分感谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-2-14 13:17:05 | 显示全部楼层
本帖最后由 BaiBai2011 于 2014-2-14 13:24 编辑
  1. #include<stdio.h>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-2-14 13:18:03 | 显示全部楼层
本帖最后由 BaiBai2011 于 2014-2-14 13:25 编辑

请注意读用 "rb" 读取二进制文件!请注意写用 "wb"  写二进制文件!
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. void main()
  4. {
  5.         FILE *picture,*file,*finish;
  6.         char picture_name[20],file_name[20],finish_name[20];
  7.         char ch;

  8.         printf("请输入需要合成的图片和文件的名称:  \n");
  9.         printf("图片:  ");
  10.         scanf("%s",picture_name);
  11.         printf("文件:  ");
  12.         scanf("%s",file_name);
  13.         printf("生成的文件名称:  ");
  14.         scanf("%s",finish_name);

  15.         if(!(picture=fopen(picture_name,"rb")))
  16.         {
  17.                 printf("Cannot open the picture %s !",picture_name);
  18.                 return;
  19.         }
  20.         if(!(file=fopen(file_name,"rb")))
  21.         {
  22.                 printf("Cannot open the file %s !",file_name);
  23.                 return;
  24.         }
  25.         if(!(finish = fopen(finish_name,"wb")))
  26.         {
  27.                 printf("Cannot open the finish %s !",finish_name);
  28.                 return;
  29.         }

  30.         while(!(feof(picture)))
  31.         {
  32.                 ch = fgetc(picture);
  33.                 fputc(ch,finish);
  34.         }
  35.         fclose(picture);
  36.         while(!(feof(file)))
  37.         {
  38.                 ch = fgetc(file);
  39.                 fputc(ch,finish);               
  40.         }
  41.         fclose(file);
  42.         fclose(finish);

  43.         system("pause");
  44. }
复制代码



小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-2-14 13:30:13 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-2-16 09:01:56 | 显示全部楼层
顶一下哈~
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-8 10:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表