View Single Post
Old 04-24-2002, 06:53 PM   #2
Yui Unifex
Senior Member
 
Join Date: Apr 2002
Location: Florida
Posts: 323
Yui Unifex is on a distinguished road
Send a message via ICQ to Yui Unifex Send a message via AIM to Yui Unifex
Question

Yes you must have a multidimensional array to handle this sort of thing. But I'm guessing that you're not properly handling this array, and that's what's causing your problems. Here's an implementation that should work. A note of warning though, it's untested =)

[code] /* on the character structure */
char **storage;
int storage_size;

/* on character initialization */
character->storage_size = 0;

/* in your storage command */
int i;
char **new_storage;

++character->storage_size;
new_storage = malloc(sizeof(char **) * character->storage_size);

for (i = 0; i < character->storage_size - 1; ++i)
new_storage[i] = character->storage[i];
free(character->storage);

new_storage[character->storage_size - 1] = strdup(new_thing_to_store);
character->storage = new_storage;

/* on character deletion */
int i;
for (i = 0; i < character->storage_size; ++i)
free(character->storage[i]);
free(character->storage);[/quote]

It would be wisest to make those into seperate functions that operate on the storage array and size, but that should give you an idea of how to do it.
Yui Unifex is offline   Reply With Quote