-3
我需要用C語言編寫文件中結構地址的值。如何在C中編寫文件結構的地址C
void func_1 (struct_1 *st)
而且位於file.h類型struct_1
struct struct_1 {
target_ulong a;
target_ulong b;
uint32_t c;
uint16_t size;
}
我在file.txt文件編寫這些代碼
FILE *fp;
fp=fopen("/path/to//doc.txt", "wb");
int x=sizeof((void *)st);
fwrite (st, x, 100, fp);
fclose(fp);
,結果是這樣的,當我打開doc.txt
地址指向內存位置。他們不指向文件中的位置。 –
你希望在'x'中有什麼價值?如果你想要使用'sizeof(* st)'的結構體的大小。 –
作爲@Chris的寫法,sizeof((void *)x)將返回一個void指針的大小。 – Lou