catom_w 2014-06-30 03:07 采纳率: 40%
浏览 2039
已采纳

c图片文件读取问题,坐等大神

enter code here

void fileCopy( const char * targetFilePath, const char * toPlace ){

FILE * istream, * ostream;  // 
if(( istream = fopen( targetFilePath, "r" )) == NULL ){
    printf("文件不存在!");
    exit( 0 );
}
ostream = fopen( toPlace, "w");
char ch;
while( (ch=fgetc(istream)) != EOF ){
    cout<<ch<<"  ";
    fputc( ch, ostream );
}
fclose( ostream );

}

void main( ){
// const char * from = "D://a.jpg";
// const char * to = "D://b.jpg";
const char * from = "D://data.txt";
const char * to = "D://b.txt";
fileCopy( from, to );
cout<<"完成!"<<endl;
}
为什么复制txt文件读取没问题,但是复制图片文件有问题,望大神求解?

  • 写回答

1条回答 默认 最新

  • xfzztd 2014-06-30 10:40
    关注

    图片一般是二进制的,用fread/fwrite接口,并用二进制读写模式就可以了。fgetc/fputc更多的是处理文本的。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真