Sigh, I had a long response to this post but I somehow lost it.  I'll try
to give a rough summary of it.  If the original shows up at some point,
just ignore it.

My advice is to scrap this snippet and start over.  It looks to be poorly
thought out.  For instance, your structure for holding a wordlist.  It is
set up to be part of a linked list (via the next pointer) but is never
used this way.

Also, why are first and last pointers to chars rather than chars?  That
causes complication later on like this:
                fl = UPPER(arg2[0]);
                el = UPPER(arg3[0]);
                sprintf(first_l,"%c",fl);
                sprintf(last_l,"%c",el);
                pWrd->first = first_l;
                pWrd->last = last_l;

These are just nitpicks of course, but the snippet overall doesn't flow
well.  It looks like the entry point is wordlist_cc() but there is an
infinite loop, and two potential core dumps in there since pWrd is never
intialized.
                        if(pWrd->guess_count > 0 )
                        {
                        for(i = 0 ; i < pWrd->guess_count ; i++ )
                        {
                                sprintf(word,"%s",pWrd->guesses[i]);
                                sprintf(name,"%s",pWrd->guessers[i]);
                        }
                        }
You never set pWrd->guess_count to 0, so it could be anything.  If it
happened to be 1, then this is probably going to coredump when it accesses
pWrd->guesses[i] because you do not call calloc on that until
do_wtcorrect().

Your code should protect itself from you.  Meaning if function X should be
used to initialize pWrd, then function Y should return if X has not been
called.  Here is one way to do that:

during mud bootup:
   pWrd = NULL;

function X (initializes wordlist engine):
   pWrd = malloc()
   /* initialization here */

function Y (does some operation on the engine, such as starting a new game):
   if( !pWrd )
   {
      send_to_char( "wordlist not intialized. call function X first\n\r",
ch );
      return;
   }

function Z (unload the engine):
   free( pWrd );
   pWrd = NULL;

A lot of people that learned other languages before C (like java) tend to
forget that C will not initialize data for you.  You need to set every
variable before you can be sure what it is.  Declaring an int does not
mean it will equal 0.  It /may/ but it is not guaranteed to be.

There are numerous other little problems with the code, which I won't go
into detail because I believe the way to fix this code is to go back to
the design of it and make it clean and simple.

I have a snippet in my mud that I did not go back to the drawing board on
when I should have - I still can't find the bug in it after a few years of
looking :)  So take your time and design it properly.  Trying to fit a
square peg in a round hole will only cause you more headaches in the long
run.

> OK, well im posting everything in wordtwist.c and everything that should
> go
> with it(kinda like a snippet that doesnt work;) ) at
> http://www.angelfire.com/apes/tristaniso/wordtwist.txt
>
> look for:
> void do_wtcorrect(CHAR_DATA *ch, char *argument)
> and
> void do_guesswt(CHAR_DATA *ch, char *argument)
>
> those are where guesses are dealt with
>
> btw, please forgive how crude all this surely is...its the best of my
> abilities;)
>
>>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: Mon, 23 Aug 2004 17:21:24 -0700
>>
>>Oh! Did you use my little code snippet back in one of the posts? Heh.
>>Well, uhh, show me what ya got. Like, how you make a guess, and how
>>its added to the guess, and where guess_count is increased. Cause it
>>should only increase when a guess is added to the list.
>>
>>Davion
>>
>>--
>>ROM mailing list
>>[email protected]
>>http://www.rom.org/cgi-bin/mailman/listinfo/rom
>
> _________________________________________________________________
> Designer Mail isn't just fun to send, it's fun to receive. Use special
> stationery, fonts and colors.
> 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*.
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
>


Reply via email to