从文件读入结构体,打印结构体至文件

#include 

typedef struct _test_struct
{
  u16 pam1;
  u16 pam2;
  u16 pam3;
  u16 pam4;
}test_struct;

char *read_path= "./exp1.bin"
char *write_path = "./exp_new1.bin"

int main()
{
  test_struct struct_read ;

  FILE *read_fp ;
  read_fp = fopen(read_path,"rb");
  if(NULL == read_fp)
  {
      printf("open fail"); 
      return -1;
  }

  fread(&struct_read, sizeof(test_struct), 1, read_fp);

  printf("%d\n", struct_read.pam1);

  FILE *golden;
  golden = fopen(write_bin , "wb");
  
  fwrite(&struct_read , sizeof(test_struct) , 1, golden);

  fclose(read_fp);
  fclose(golden);



}

你可能感兴趣的:(C,c++)