H
hal
Hi,
I'm trying to make an array of pointers to 'TwoCounts' structs, where
the size of the array is arraySize. Right now I'm just mallocing
enough space for all the pointers to the structs, and mallocing space
for the pointer 'countPtr' in each struct, but do I need to do
anything else? Thanks.
typedef struct TwoCounts {
int *countPtr;
int count;
} TwoCounts;
int j;
TwoCounts *twoCountsArray;
TwoCounts *tempPtr;
twoCountsArray = (TwoCounts *) malloc(arraySize * sizeof(TwoCounts
*));
for (j=0;j<arraySize;j++){
//get location of each pointer in the array
tempPtr = (twoCountsArray + arraySize * sizeof(TwoCounts *));
//initialize the countPtr
tempPtr->countPtr = (TwoCounts *) malloc (sizeof(int));
*(tempPtr->countPtr) = NULL;
}
I'm trying to make an array of pointers to 'TwoCounts' structs, where
the size of the array is arraySize. Right now I'm just mallocing
enough space for all the pointers to the structs, and mallocing space
for the pointer 'countPtr' in each struct, but do I need to do
anything else? Thanks.
typedef struct TwoCounts {
int *countPtr;
int count;
} TwoCounts;
int j;
TwoCounts *twoCountsArray;
TwoCounts *tempPtr;
twoCountsArray = (TwoCounts *) malloc(arraySize * sizeof(TwoCounts
*));
for (j=0;j<arraySize;j++){
//get location of each pointer in the array
tempPtr = (twoCountsArray + arraySize * sizeof(TwoCounts *));
//initialize the countPtr
tempPtr->countPtr = (TwoCounts *) malloc (sizeof(int));
*(tempPtr->countPtr) = NULL;
}