I have a pointer array of a custom Vector typedef (just 3 floats). I'm writing a Wavefront object loader and I want to be able to add to an array of these vectors whenever a vertex row in the file is encountered. My problem at the moment is allocating memory for the new vector.
Vector
typedef struct
{
float x;
float y;
float z;
}
Vector;
Parsing the line and saving in memory
Vector *verticies;
Vector tmp;
verticies = new Vector;
long endPtr = sizeof(verticies);
sscanf(line, "v %f %f %f", &verticies[endPtr].x, &verticies[endPtr].y, &verticies[endPtr].z);
return;
There are eight vertices in the .obj file and the output of sizeof(verticies) shows 8 all the time. The problem with the code above is that the new vertex is given to the last element in *verticies, so my question is; ** how do I add elements to the end of a pointer array dynamically?**
operator new. Everything else is pure C.