I know this will sound really newbish, but i gotta ask it anyway. right now, when i have things like pWrd-> it compiles no errors, no warnings but at the first occurence of pWrd->newround it crashes, when i used wordtwist.<whatever> i didnt have these problems(but the strings didnt want to strcat properly or something) so im trying this, but my question is how i can make these work, so they dont have to be initialized every time i use them etc...ive been toying around with this for a long time with no luck:p

From: Davion Kalhen <[EMAIL PROTECTED]>
Reply-To: Davion Kalhen <[EMAIL PROTECTED]>
To: [email protected]
Subject: Re: a problem with checking if a word has been entered already
Date: Sun, 22 Aug 2004 16:25:57 -0700

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

--
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom

_________________________________________________________________
Take charge with a pop-up guard built on patented Microsoft® SmartScreen Technology. http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines Start enjoying all the benefits of MSN® Premium right now and get the first two months FREE*.


Reply via email to