When ever I'm bulding a dynamic list like that, and keep track of
things. I always like to allocate it myself. Its something I've used
for awhlie, prolly a waist, but its simple, it works, and hey, Muds
don't need to be nit-picked code :P. But, well, if someone is really
against this and doesn't like it, send, tell me why, etc. Always like
explinations. Buut.
struct wordtwist
{
int guess_count;
char first;
char last;
char *word;
char **guesses;
char **guessers;
};
void guess_to_twist(char *guess, struct wordtwist *pWrd, CHAR_DATA *guesser )
{ if( pWrd->guess_count == 0 )
{ pWrd->guesses = calloc(sizeof(char * ), 1 );
pWrd->guessers = calloc(sizeof(char *), 1 );
pWrd->guess_count++;
*pWrd->guesses = str_dup(guess);
*pWrd->guessers = str_dup(guesser->name);
return;
}
pWrd->guess_count++;
pWrd->guesses = realloc(pWrd->guesses, sizeof(char * ) *
pWrd->guess_count );
pWrd->guessers = realloc(pWrd->guesses, sizeof(char *) *
pWrd->guess_count);
pWrd->guess_count++;
pWrd->guesses[pWrd->guess_count-1] = str_dup(guess);
pWrd->guessers[pWrd->guess_count-1] = str_dup(guesser->name);
return;
}
Then to see if its been guessed, you can have something like
bool has_been_guessed( struct wordtwist *pWrd, char *word )
{ int i;
for( i = 0 ; i < pWrd->guess_count ; i++ )
if(!str_cmp(word, pWrd->guessed[i]) )
return TRUE;
return FALSE;
}
That way, you'll never have the same thing guessed twice. I hope it
makes sense. I just whipped this code up, never been compiled/tested,
totally freehand :) So use more as a concept than the building blocks.
I hope this helps!!
Davion