serbet
April 28th, 2003, 08:26 AM
The are a lot of numeric variables, values of which changes often and often. Such as:
int a;
float b;
float c;
These values must be written to a file. I thought a shiny idea: If I declare a structure, items of which are a pointer to these variables, it would be better to work. Rather than writing the data variable by variable, I would write only the struct after every update of values. The struct is as the following:
typedef struct{
int* a;
float* b;
float* c;
}dat;
Only I must do is to assign the adresses of the variables to these pointers at the beginning of the program like this:
dat.a = &time;
dat.b = &pitch;
dat.c = &roll;
But when I do the following:
dat data;
fwrite(&data,sizeof(dat),1,fp);
of course, not the values, the adresses of variables are written to the file.
and my shiny idea, peah!
in this way, I'm looking forward to get your ideas! It's possible to use a structure with pointer logic?
int a;
float b;
float c;
These values must be written to a file. I thought a shiny idea: If I declare a structure, items of which are a pointer to these variables, it would be better to work. Rather than writing the data variable by variable, I would write only the struct after every update of values. The struct is as the following:
typedef struct{
int* a;
float* b;
float* c;
}dat;
Only I must do is to assign the adresses of the variables to these pointers at the beginning of the program like this:
dat.a = &time;
dat.b = &pitch;
dat.c = &roll;
But when I do the following:
dat data;
fwrite(&data,sizeof(dat),1,fp);
of course, not the values, the adresses of variables are written to the file.
and my shiny idea, peah!
in this way, I'm looking forward to get your ideas! It's possible to use a structure with pointer logic?