|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我这个代码基本是按照小甲鱼老师的流程写下来的,可以运行,但是当我把后缀名从jpg改成rar的时候,就打不开了,请问大神有没有发现问题,谢谢大佬们了。
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp, *pp, *rp;
char filename[20], picturename[20], rarname[20], ch;
printf("please write the filename :\n");//输入需要打开的新建文件名称
scanf("%s", filename);
if (!(fp = fopen(filename, "wb")))//验证新建文件是否被打开
{
printf("there is no file can been open\n");
}
printf("please write the picturename :\n");//输入需要打开的照片文件名称
scanf("%s", picturename);
if (!(pp = fopen(picturename, "rb")))//验证照片文件是否被打开
{
printf("there is no picturefile can been open\n");
}
printf("please write the rarname :\n");//输入需要打开的压缩文件名称
scanf("%s", rarname);
if (!(rp = fopen(rarname, "rb")))//验证压缩文件是否被打开
{
printf("there is no rarfile can been open\n");
}
while (!(feof(pp)))
{
ch = fgetc(pp);
fputc(ch, fp);
}
fclose(pp);
while (!(feof(rp)))
{
ch = fgetc(rp);
fputc(ch, rp);
}
fclose(fp);
fclose(rp);
system("pause");
}
本帖最后由 jackz007 于 2019-3-5 21:22 编辑
代码逻辑很乱,楼主是否可以把实现思路线索大致说一下,看你的代码无非就是简单的二进制文件复制,并不涉及到 jpg 和 rar 格式相关的实质性操作。
- if (!(rp = fopen(rarname, "rb"))) //为二进制读打开文件
- . . . . . .
- while (!(feof(rp)))
- {
- ch = fgetc(rp) ; //二进制读,合法操作
- fputc(ch , rp) ; //从同一个文件读写数据不知有何意义?
- }
- . . . . . .
复制代码
|
|