Search code examples
cbinaryfiles

how to display binary result written in a file with c language


I need to write the value of the address of a struct in file with C language.

void func_1 ( struct_1 *st)

And the type struct_1 located at a file.h

struct struct_1 {
      target_ulong a;   
      target_ulong b; 
      uint32_t c; 
      uint16_t size;
}

I write in the file file.txt with this code

FILE *fp;
fp=fopen("/path/to//doc.txt", "wb");
int x=sizeof((void *)st);
fwrite (st, x, 100, fp);
fclose(fp);

And the result is like that when I open the doc.txt

enter image description here

It seems that the format of the file can't be open with gedit. can you propose another tools to open it.


Solution

  • the problem was with the editor who by default search the ASCII code and display character in this case i open the file in order to write in binary mode so that's why the problem occurs

    i used A HEXADECIMAL editor that can open and display binary file