--- Brett Phipps <[EMAIL PROTECTED]> wrote:
> > > void add_trophy (CHAR_DATA *ch, CHAR_DATA *victim)
> > > {
> > >    int i = 0;
> > >    TROPHY_DATA * trophy;
> > >
> > >    /* If were the first entry, set it up */
> > >    if (ch->pcdata->trophy_list->next == NULL)
> >
> >Where are you initializing ch->pcdata->trophy_list?
> >You neglected to show that code.
> 
> Well, I have a call in new_pcdata in recycle.c that initializes
> trophy_list using new_trophy_data();.  In doing this it sets the
> trophy_list->next to NULL.  So I assume here that if it's null an actual
> ->pcdata->trophy isn't initialized yet.

I believe you want it to be initialized to NULL since at the point you are
creating a new character you want to have an empty list.

> >You seem to be a bit confused on linked lists.
> >Either you use an empty head node, like you seem to be doing here,
> >or you treat the case of adding to an empty list specially, also
> >like you seem to be doing.  Not both.  If you're initializing
> >ch->pcdata->trophy_list somewhere to an empty value, the whole
> >first part of this function (everything inside this if) is
> >unnecessary.  The code below takes care of it.
> 
> You are correct here.  What I intended to do is have trophy_list be
> the empty head node.  I initialize trophy_list like I mentioned above
> and I believe I'm trying to initialize a first "instance" of a trophy
> structure as trophy_list should point to NULL if there aren't any actual
> trophy's set yet.

Actually the head of the list is the pcdata->trophy_list. To make it point to
NULL in the event of an empty list is correct, and as such the code in
recycle.h should be nothing more than 

ch->pcdata->trophy_list = NULL;


> >What are you using ch->pcdata->trophy for?
> >It looks to me like you're using it instead of using the
> >local variable trophy in this function?
> 
> Indeed I am.  An error on my part, still haven't gotten my head
> completely wrapped around Linked lists.

Yeah, that variable is unnessicary.

> > >        strcat(ch->pcdata->trophy->short_desc, victim->short_descr);
> >          ^^^^^^
> >Big no no.  Don't ever do this unless you have a large character
> >buffer (you don't here.  All you have is a pointer)
> 
> Thanks for the heads up.  When dealing with copying strings of this
> nature, what is the prefered method to do it?

Well assuming that the trophy->short_desc just points to NULL as it was
initialized in the new_trophy_data function.. You'd want to do this:

trophy->short_desc = str_dup(victim->short_descr);

Just be sure to call:

free_string(trophy->short_desc)

later to clean it up.

> It would seem to me at least that keeping a seperate empty "start of
> list" variable would be the easiest way to keep track of things.
> But I could very well be wrong on this as well.  At any rate, thanks for the 
> response.  I will be keeping on this until I get it working properly, so 
> expect another question or two in the coming days.


The easist way to represent an empty linked list is to have the head pointer
point to NULL.


Hope that helps,

~Kender (back from lurking)

=====
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/L/C/O d-(+) s++: a-- C+++$>++++ UBLS++++$ 
P+++(--)$ L+++>++++ E--- W+>++$ N !o K? w(--) !O 
M- !V PS+ PE(++) Y+ PGP->+ t+ 5 X+() R(+) tv+@ 
b++(+++) !DI+++ D G(-) e>+++$ h---() r+++ y+++
------END GEEK CODE BLOCK------

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

Reply via email to