Hi all,
I need some help. Could somebody please tell me what is wrong with this code, or maybe suggest a better way to do this.
typedef struct {
long Size;
double Data[1];
} Struct2;
typedef Struct2 **Struct2Hdl;
typedef struct {
double f0;
double df;
Struct2Hdl Array;
} Struct1;
int main (void)
{
Struct1 *Data;
/* Allocate memory for Data structure
Data= (Struct1 *) malloc(sizeof(Struct1));
/* Allocate memory for Array handle
(*Data).Array = (Struct2**)malloc(sizeof(Struct2));
/* Allocate memory for Size element of Array hanle
(*(Power)->Array)->Size = (long*)malloc(sizeof(long));
When i compile i get the following error due to the last line:
error C2440: '=' : cannot convert from 'long *' to 'long'
I know malloc will return a 'long *' but how do i allocate memory to 'Size' and 'Data'
How do i allocate memory for the elements of the structures. If i don't allocate memory i get an 'Unhandled exception error'. Or is there a better way to allocate memory for these complicated structures. Do i have to allocate memory for each elemnt in the structure and what if one of the elements is itself a handle to another structure. How do i allocate memory for it
Thanks
I need some help. Could somebody please tell me what is wrong with this code, or maybe suggest a better way to do this.
typedef struct {
long Size;
double Data[1];
} Struct2;
typedef Struct2 **Struct2Hdl;
typedef struct {
double f0;
double df;
Struct2Hdl Array;
} Struct1;
int main (void)
{
Struct1 *Data;
/* Allocate memory for Data structure
Data= (Struct1 *) malloc(sizeof(Struct1));
/* Allocate memory for Array handle
(*Data).Array = (Struct2**)malloc(sizeof(Struct2));
/* Allocate memory for Size element of Array hanle
(*(Power)->Array)->Size = (long*)malloc(sizeof(long));
When i compile i get the following error due to the last line:
error C2440: '=' : cannot convert from 'long *' to 'long'
I know malloc will return a 'long *' but how do i allocate memory to 'Size' and 'Data'
How do i allocate memory for the elements of the structures. If i don't allocate memory i get an 'Unhandled exception error'. Or is there a better way to allocate memory for these complicated structures. Do i have to allocate memory for each elemnt in the structure and what if one of the elements is itself a handle to another structure. How do i allocate memory for it
Thanks