怎么在C里面读二进制文件?

SpritToT 2002-03-29 05:55:50
怎么在C里面读二进制文件?
...全文
128 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
anyyan 2002-04-05
  • 打赏
  • 举报
回复
FILE *fp; //读二进制文件proc_dat
if((fp=fopen("proc_dat","rb"))==NULL)
{
printf("cannot open this file\n");
exit(0);
}
for(i=1;i<=SIZE;i++)
{
fgets(Value,3,fp);//Value存放读到的数据(3表示字符数,fp指针读完一个自动加1)
getc(fp); //我的文件中有空格
}
fclose(fp);


看不懂就去看书。一般要根据具体的文件形式及数据格式做相应改变的。
poly30 2002-04-05
  • 打赏
  • 举报
回复
c语言书上一般都有例子

找本书看就行了
zhaoweikid 2002-04-05
  • 打赏
  • 举报
回复
能不能给一个完整的程序?
divaly 2002-03-30
  • 打赏
  • 举报
回复
fopen打开文件,rb+二进制文件,
fread读文件
fseek定位文件
prototype 2002-03-29
  • 打赏
  • 举报
回复
it is:

FILE* file1; // not 'file'
file1=fopen("temp.dat","r+b"); // not '+rb'
// fread(*file,1,1,size()); is wrong
// see the following for correct usage.

Declaration:

size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
Reads data from the given stream into the array pointed to by ptr. It reads nmemb number of elements of size size. The total number of bytes read is (size*nmemb).
On success the number of elements read is returned. On error or end-of-file the total number of elements successfully read (which may be zero) is returned.

林雨亭 2002-03-29
  • 打赏
  • 举报
回复
注意:字节的顺序
wiler 2002-03-29
  • 打赏
  • 举报
回复
fopen("Filename.dat","+rb");
panpasspanpass 2002-03-29
  • 打赏
  • 举报
回复
wo tongyi
panpasspanpass 2002-03-29
  • 打赏
  • 举报
回复
a up
yang__ling 2002-03-29
  • 打赏
  • 举报
回复
file *file1;
file1=fopen("temp.dat",+rb); //加一个B
fread(*file,1,1,size()); //再调用FREAD();
freewing 2002-03-29
  • 打赏
  • 举报
回复
用二进方式打开后读就是了。fread

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧