我有這樣的事情,其實更復雜的結構比這如何保存動態結構到文件
typedef struct _sample {
unsigned char type;
char *name;
test *first;
} sample;
typedef struct _test {
test *prev;
test *next;
char *name;
int total;
test_2 **list;
} test;
typedef struct _test_2 {
char *name;
unsigned int blabla;
} test_2;
sample *sample_var;
我想備份這個結構到一個文件後恢復它。
我也嘗試fwrite(sample_var, sizeof(sample), 1, file_handle);
,但真正的問題是sizeof(sample)
返回錯誤的大小,而不是實際的可變大小。
有一種方法可以將它保存到文件中&恢復不知道大小?
@OP是否讓我們知道它是否可以使用。 – cnicutar 2011-08-17 12:08:51