Hello,
I am new to using Pointer to pointers rather than 2 dimensional arrays, but it is about time i needed dynamic memory.
Anyways, I typedef-ed a struct as follows:
Code:
typedef struct {
float **vertex;
float **face;
} MODEL;
And I have a function that is called from main() which takes a 'MODEL' pointer as parameters. I need to allocate memory for it to be similar to, if using arrays, array[3][valuesRecieve], and here is what I did:
Code:
/* I want vertex to be [3][vertices]*/
*(m->vertex) = malloc(sizeof(float)*3);
m->vertex = malloc(sizeof(float)*vertices);
/* I want face to be [2][faces]*/
*(m->face) = malloc(sizeof(float)*2);
m->face = malloc(sizeof(float)*faces);
But the program encounters error and exits. Any idea why?
PS: 'm' is the pointer to a MODEL in the parameters of the function.
Thank you,
abraham2119