I am trying to assign an int pointer to an int array which is a member of a structre. The structure is a member of another structure, which happens to be an array of structures. And this array of structures happens to be a member of another structure. And this last structure happens to be an element of an array of structures.
typedef struct s_ptxRowProperties
{
int lastPlotValue[134];
} ptxRowProperties;
typedef struct s_ptxRow
{
ptxRowProperties PtxRowProperties;
} ptxRow;
typedef struct s_workSpace
{
ptxRow PtxRow[100];
} workSpace;
Edit: I allocate 1 of these behemoths like this: WorkSpace[n] = (workSpace *) calloc(1, sizeof(workSpace));
I have tried the following incantations, to no avail:
int *x= &(WorkSpace[i]->PtxRow[ptxRowIndex].PtxRowProperties.lastPlotValue)[0];
int *x= (&WorkSpace[i]->PtxRow[ptxRowIndex].PtxRowProperties.lastPlotValue)[0];
int *x= &(WorkSpace[i]->PtxRow[ptxRowIndex].PtxRowProperties->lastPlotValue)[0];
int *x= WorkSpace[i]->PtxRow[ptxRowIndex].PtxRowProperties.lastPlotValue;
int *x= *(WorkSpace[i]->PtxRow[ptxRowIndex].PtxRowProperties.lastPlotValue);
int *x= (*WorkSpace[i]->PtxRow[ptxRowIndex].PtxRowProperties->lastPlotValue);
I believe the hypothetical million monkeys in a room for 100 years will have composed Hamlet before they can create the correct form for this. Any ideas?
2 Answers 2
You probably want
int *x= &(WorkSpace[i]->PtxRow[ptxRowIndex].PtxRowProperties.lastPlotValue[0]);
This assumes that WorkSpace[i]->PtxRow[ptxRowIndex].PtxRowProperties.lastPlotValue[0] would reference the first element of the int array.
2 Comments
->lastPlotValue instead. Or maybe he should just post the structs so we don't need to guess...If WorkSpace[i]->PtxRow[ptxRowIndex].PtxRowProperties.lastPlotValue is the value you are interested in, than one would use & to get its address:
int *x = &WorkSpace[i]->PtxRow[ptxRowIndex].PtxRowProperties.lastPlotValue;
4 Comments
Warning - incompatible pointer types initializing 'int *' with an expression of type 'int (*)[134]'.
WorkSpace[i]->PtxRow[ptxRowIndex].PtxRowProperties?