|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 slmdunk 于 2016-12-3 16:02 编辑
//1.需要修改的文件 在源文件目录内
//2.绝对路径测试仍然无法找到待复制文件
//可参考图片
//二进制文件操作复制两个文件至第三个新建按文件
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fl_pic,*fl_file,*fl_finish;
char pic_name[20],file_name[20],finish_name[20],ch;
printf("图片:");
scanf("%s",pic_name);
printf("文件:");
scanf("%s",file_name);
printf("生成的文件名:");
scanf("%s",finish_name);
if(NULL==(fl_pic=fopen(pic_name,"rb")))//若打开不成功返回null 只读文件1二进制数据
{
printf("Cannot open the picture %s\n",pic_name);
return;
}
if(!(fl_file=fopen(file_name,"rb")))//同上 文件2的读取
{
printf("Cannot open the file %s\n",file_name);
return;
}
if(!(fl_finish=fopen(finish_name,"wb")))//写入二进制数据
{
printf("Cannot open the finish %s\n",finish_name);
return;
}
//循环
while(!feof(fl_pic))
{
ch=fgetc(fl_pic);//获取一个二进制数据
fputc(ch,fl_finish);
}
fclose(fl_pic);
while(!feof(fl_file))
{
ch=fgetc(fl_file);
fputc(ch,fl_finish);
}
fclose(fl_file);
fclose(fl_finish);
system("pause");
}
//第四张图在二层
//请朋友们帮我查找原因 小甲鱼在视频中并未说明 我也查了资料利用绝对路径也未能实现
//结论总是找不到文件!!
我没有时间帮你看你的程序是否有错,将我的程序直接发给你
- #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];
-
- printf("请输入需要合成的两个文件的名称:\n");
- printf("第一个文件名:");
- scanf("%s",pic_name);
- printf("第二个文件名:");
- scanf("%s",file_name);
- printf("合成的文件名称:");
- scanf("%s",finish_name);
-
- if( !(f_pic = fopen(pic_name,"rb")))
- {
- printf("Cannt open the picture %s !",pic_name);
- return;
- }
- if( !(f_file = fopen(file_name,"rb")))
- {
- printf("Cannt open the file %s !",file_name);
- return;
- }
- if( !(f_finish = fopen(finish_name,"wb")))
- {
- printf("Cannt open the file %s !",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);
- printf("两文件已成功合成! \n");
- printf("\n");
- system("pause");
- }
复制代码
|
-
G盘结果
-
G盘结果,截图错了应该是G:\\1.jpg等等
-
源文件目录下结果
|