Reputation: 5187
I have an array of structs that I have defined in a header file:
struct table {
otherStruct *list[16];
}
Now I want to be able to resize this array, change the size of the array, or dynamically allocate an array that can replace (or join) the original list in "table" once a condition is met. How can I accomplish this task?
Upvotes: 1
Views: 1577
Reputation: 12515
Change the array to a otherStruct ** and malloc a group of (otherStruct *) to the new size of your array. Be sure to free it as well as this will be a new alloc on top of your old ones.
Upvotes: 1
Reputation: 56059
Make list
an otherStruct **
:
struct table {
otherStruct **list;
}
Now you can malloc
it to be as big as you want and realloc
at will.
Upvotes: 5