N
nmtoan
Hi,
I could not find any answer to this simple question of mine.
Suppose I have to write a program, the main parts of it are as follows:
#include <blahblah.h>
struct
{
double *my_dynamic_variable1;
int **my_dynamic_variable2;
char ***my_dynamic_variable3;
} gv;
main()
{
FILE *fbinary;
fbinary = fopen("test.bnr","wb");
ALLOCATE memory for gv.my_dynamic_vairable1, 2 and 3;
fwrite(gv,sizeof(gv),1,fbinary);
....
}
The problem is that, since gv is dynamically allocated at run-time, and
gv contains various variable types, how can I correctly find the actual
size of the variable gv, in order to write it corerctly to the file?
The same question raised when reading gv from a binary file. Is there
any alternative (but elegant way) of finding the size of gv, without
using sizeof?
I could not find any answer to this simple question of mine.
Suppose I have to write a program, the main parts of it are as follows:
#include <blahblah.h>
struct
{
double *my_dynamic_variable1;
int **my_dynamic_variable2;
char ***my_dynamic_variable3;
} gv;
main()
{
FILE *fbinary;
fbinary = fopen("test.bnr","wb");
ALLOCATE memory for gv.my_dynamic_vairable1, 2 and 3;
fwrite(gv,sizeof(gv),1,fbinary);
....
}
The problem is that, since gv is dynamically allocated at run-time, and
gv contains various variable types, how can I correctly find the actual
size of the variable gv, in order to write it corerctly to the file?
The same question raised when reading gv from a binary file. Is there
any alternative (but elegant way) of finding the size of gv, without
using sizeof?