鱼C论坛

 找回密码
 立即注册
查看: 1765|回复: 1

c语言初学求助

[复制链接]
发表于 2020-2-16 17:19:50 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 超级甲鱼粉 于 2020-2-16 17:19 编辑

写了一个图片文件合成的程序,图片是JPG形式的,合成的文件是rar形式,要合成一个rar形式的文件。文件和图片都在程序的文件夹里,但是用fopen函数总是打不开图片,换了图片也是一样打不开,求解,十分感谢。#include <stdio.h>
#include <stdlib.h>

void main()
{
        FILE *f_pic , *f_file , *f_finish;                                                                                          我没办法上传图片,过程就是:
        char ch , pic_name[20] , file_name[20] , finish_name[20];                                                     这个程序的文件里有一个压缩文件1.rar和一个图片2.jpg
                                                                                                                                           我先输入2.jpg再输入1.rar再输入3.jpg就会出现Cannot open the picture 2.jpg
        printf("Please input the name of the picture and file's names :\n");
        printf("picture :");
        scanf("%s",&pic_name);
        printf("file :");
        scanf("%s",&file_name);
        printf("finish :");
        scanf("%s",&finish_name);

        if( !(f_pic = fopen(pic_name , "r")))
        {
                printf("Cannot open the picture %s\n",pic_name);
                return;
        }
        if(!(f_file = fopen(file_name , "rb")))
        {
                printf("Cannot open the file %s\n",file_name);
                return;
        }
        if(!(f_finish = fopen(finish_name , "wb")))
        {
                printf("Cannot open the file %s\n",finish_name);
                return;
        }

        while(!(feof(f_pic)))
        {
                ch = fgetc(f_pic);
                fputc(ch,f_finish);
        }
        fclose(f_pic);

        while(!(feof(f_file)))
        {
                ch = fgetc(f_file);
                fputc(ch,f_finish);
        }
        fclose(f_file);
        fclose(f_finish);

        system("pause");
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-2-24 14:39:15 | 显示全部楼层
我把你的代码复制了一边 一切OK  就是没生成文件
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-19 13:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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