-
allocating memory?
I have a structure which holds 3 float numbers, I'd like to create an array of this structure of size "iNumberVertices" (an integer).
I'm doing it like this at the moment, but it's not working, could anybody help me out? Here's my code:
Code:
struct vect
{
float x, y, z;
};
struct vect pVerts = vect[iNumberVertices];
-
use malloc() to allocate the space. and pVerts must be a pointer.
Code:
struct vect* pVerts = malloc(iNumberVertices * sizeof(struct vect));
-
You should also include <stdlib.h> for any memory allocation functions (malloc, calloc, realloc, and free).
And free your malloc()ed memory when you're done with it.