日期:2014-05-16  浏览次数:20738 次

c语言 二进制文件写入的问题,求版主解决一下
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include "M_dongjieliang.h"

#define filename "meter_djl.log"

int main()
{
  FILE *fp;
  int ret;
  struct M_Dongjie_L M_DJL;
  //unsigned char *buff = "aaaaa";
  unsigned char temp[8]={0x41,0x41,0x41,0x41,0x41,0x41,0x31};
  unsigned char t[7] = {0x12,0x11,0x10,0x17,0x07,0x0d};


     fp = fopen(filename,"rb+");
       if(!fp)
          {
              fp = fopen(filename,"wb+");
              return -1;
          }
            // M_DJL.m_num =0x01;
             //memcpy(M_DJL.m_djl_val,temp,8);
            // memcpy(M_DJL.save_time,t,7);
         //ret = fwrite(M_DJL.save_time,sizeof(struct M_Dongjie_L),1,fp);
          ret = fwrite(temp,1,8,fp);
        if(!ret)
            perror("fwrite");
            printf("%d\n",ret);

      fclose(fp);
    return 0;
}



我现在需要写入的是二进制的文件,现有如下的疑惑,我想用UE 打开时显示的是这样的

但是现在显示的是这样的

,要怎么解决啊
二进制 C

------解决方案--------------------