gerrard2461 gerrard2461 - 4 months ago 18
C Question

how to write adress of struct in file in C

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

Answer Source

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 bless editor that can open and display binary file