#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("shurutupianhewenjian\n");
printf("picture:");
scanf("%s",pic_name);
printf("file:");
scanf("%s",file_name);
printf("result:");
scanf("%s",finish_name);
if(!(f_pic = fopen(pic_name,"rb")))
{
printf("cannot open the picture %s !",pic_name);
return;
}
if( !(f_file = fopen(file_name,"rb")))
{
printf("cannot open the file %s!",file_name);
return;
}
if(!(f_finish = fopen(finish_name,"wb")))
{
printf("cannot 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);
system("pause");
}
C:\Users\Administrator\CLionProjects\73\cmake-build-debug\627840.exe
shurutupianhewenjian
picture:1.jpg
file:2.rar
result:3.jpg
cannot open the picture 1.jpg !
行程已結束,退出代碼 0
uj5u.com熱心網友回復:
可能1.jpg不存在uj5u.com熱心網友回復:
用如下方式列印一下,可以知道錯誤原因if( !(f_file = fopen(file_name,"rb")))
{
printf("cannot open the file %s!",file_name);
printf("%s\n", strerror(errno)):
return;
}
需要注意,每個打開檔案都建議加上這句,并且需要引入string.h和errno.h頭檔案
uj5u.com熱心網友回復:
還是不行,圖片是我從網上隨便下載的,是不是權限問題?轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/35916.html
標籤:C語言
下一篇:C++馬走日問題
