复制一个二进制文件的内容 [英] copying the contents of a binary file

查看:283
本文介绍了复制一个二进制文件的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计的图像去coder和作为第一步,我想刚才复制的用c。即打开该文件,其内容写入新文件。下面是code,我用。

I am designing an image decoder and as a first step I tried to just copy the using c. i.e open the file, and write its contents to a new file. Below is the code that I used.

while((c=getc(fp))!=EOF)
  fprintf(fp1,"%c",c);

,其中FP是源文件和FP1是目标文件。
该程序执行没有任何错误,但图像文件(BMP)不能正常复制。我观察到复制的文件的大小更小,只有20%的图像是可见的,所有其他是黑色的。当我用简单的文本文件试过,复制完成。

where fp is the source file and fp1 is the destination file. The program executes without any error, but the image file(".bmp") is not properly copied. I have observed that the size of the copied file is less and only 20% of the image is visible, all else is black. When I tried with simple text files, the copy was complete.

你知道是什么问题?

推荐答案

请确保该变量 C 的类型是 INT 不可以 字符。换句话说,发布更多code。

Make sure that the type of the variable c is int, not char. In other words, post more code.

这是因为 EOF 常量的值通常是-1,如果你读字符作为字符 -sized值,每一个字节即 0xFF的将如下的EOF常数。随着一个 INT 额外的比特;有房有两个分开。

This is because the value of the EOF constant is typically -1, and if you read characters as char-sized values, every byte that is 0xff will look as the EOF constant. With the extra bits of an int; there is room to separate the two.

这篇关于复制一个二进制文件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆