Okay, I'm trying to learn how to dynamically allocate memory, and I figure the best way to do it is to try to make something with it and learn as I go.
Okay, what I'm trying to do is this. I want the user to be able to initialize as many verbs as he wants, and I want them all in one char pointer. nVerbs holds how many there are, so I can search through them later by going past the null terminator.
initializeVerbs(&forest, 4, "get", "drop", "take", "use");
typedef struct Room
short unsigned nVerbs;
short unsigned nNouns;
void initializeVerbs(struct Room *room, unsigned int nargs, const char *arg, ...);
void initializeVerbs(Room *room, unsigned int nArgs, const char *arg, ...)
unsigned length = 0;
room->nVerbs = nArgs;
for(count = 1; count < nArgs; count++)
length += (strlen(arg) + 1);
printf("sizeof(verbs): %i\n", sizeof(room->verbs));
printf("length = %i\n", length);
realloc(room->verbs, length); /*problem*/
room->verbs[length] = arg; /*Causes problems.*/
arg = va_arg(ap, const char *);
printf("Length: %i\n", length);
However...I have no idea what I'm doing. Please help.