I'm trying to reallocate an array of pointers in the following way:
void PhraseArgumentReallocator(PhraseArgument** phraseArgsList, int sizeOfArray) {
PhraseArgument** reallocatedPhraseArgsList = (PhraseArgument**)realloc(*phraseArgsList, (sizeof(PhraseArgument*) * (sizeOfArray + 1)) );
if (NULL != reallocatedPhraseArgsList) {
phraseArgsList = reallocatedPhraseArgsList;
}
else{
printf("Error:memory allocation failure\n");
exit(1);
}
PhraseArgument* NewphraseArgs = (PhraseArgument*)calloc(1, sizeof(PhraseArgument));
if (NULL == NewphraseArgs) {
printf("Error:memory allocation failure\n");
exit(1);
}
InitializePhraseArgumentProps(NewphraseArgs);
phraseArgsList[sizeOfArray] = NewphraseArgs;
}
But, when I try to print out the new element outside the function:
PhraseArgumentReallocator(phraseArgList, *sizeOfArray);
PhraseArgument* element = phraseArgList[*sizeOfArray];
printf("element\n");
printf("type=%d\n", element->Type);
printf("ArgumentOne=%s\n", element->ArgumentOne);
printf("ArgumentTwo=%s\n", element->ArgumentTwo);
I get an unhandled exception. What am I doing wrong here?