C
Cell
I have structures like this in my program -
typedef vector vectorstruct
{
double x, y,z;
} vector;
typedef struct verticesstruct
{
vector v;
} vertex; /*a vertex is a vector */
typedef struct trianglestruct
{
int v0,v1, v2;
}triangle;
typedef struct objectstruct
{
int nvert;
int ntri;
vertex *vert;
triangle *tri;
}object;
................
...............
later somewhere in the program i have a statement like this -
object *obj;
obj->vert = malloc( nvert * sizeof(vertex)); /* Creating an array of
vertices */
obj->tri = malloc(ntri * sizeof(triangle));
for(i=0;i<obj->nvert; i++)/* trying to take input for each vertex
which has x, y, z components as it is a vector*/
scanf("%f %f %f", &obj->vert.x, &obj->vert.y, &obj->vert.z);
^^^^^^^^ is this above notation of creating an array and then
accessing the elements correct ??
later on i also do this -
for(i=0;i<obj->ntri;i++)
scanf("%d %d %d", &obj->tri.v0, &obj->tri.v1, &obj->tri.v2);
typedef vector vectorstruct
{
double x, y,z;
} vector;
typedef struct verticesstruct
{
vector v;
} vertex; /*a vertex is a vector */
typedef struct trianglestruct
{
int v0,v1, v2;
}triangle;
typedef struct objectstruct
{
int nvert;
int ntri;
vertex *vert;
triangle *tri;
}object;
................
...............
later somewhere in the program i have a statement like this -
object *obj;
obj->vert = malloc( nvert * sizeof(vertex)); /* Creating an array of
vertices */
obj->tri = malloc(ntri * sizeof(triangle));
for(i=0;i<obj->nvert; i++)/* trying to take input for each vertex
which has x, y, z components as it is a vector*/
scanf("%f %f %f", &obj->vert.x, &obj->vert.y, &obj->vert.z);
^^^^^^^^ is this above notation of creating an array and then
accessing the elements correct ??
later on i also do this -
for(i=0;i<obj->ntri;i++)
scanf("%d %d %d", &obj->tri.v0, &obj->tri.v1, &obj->tri.v2);