I'm having an issue with pointers. I've read through 30+ posts on this subject and none match my setup. Here's what I'm trying to do:
void doSomething(myStruct **myList)
{
resizeMyList(myList,5);
myList[0] = '42';
myList[1] = '43'; // ERRORS OUT OF MEMORY
}
void resizeMyList(myStruct **theArray,int size)
{
myStruct *new_ptr = realloc(*theArray,(size * sizeof myStruct));
if(new_ptr)
*theArray = new_ptr;
else
printf("died");
}
After my resize function executes myList fails to get the new pointer. What am I doing wrong?
You do
myList[0] = ...
but myList
is a double pointer so it should be
(*myList)[0] = ...
Also, you try to assign multi-character literals to a structure.