[NEWBIE][CODE}] Linked List Trouble :(

From: Pure Krome (Pure@SPRINT.COM.AU)
Date: 04/27/98


G'Day.
    i'm having my daily dosage of linked list trouble. Any help will be
appreciated.

I have this function (based upon the earlier posting about blood in
rooms ..) and i'm trying
to create a linked list that contains a list of rooms which ONLY contain
blood (and in the future, blood related room thingies - like body parts,
etc ... whatever ..)

Anyways, it never _remembers_ what has been created .. For example. If
the function is called (listed below), it creates a new structure, but
never remembers it when it leaves. It's obvious that it's some scope
error on MY behalf. I've tried various things, but just can't seem to
grasp it!

Here is da code.

db.c  <near the top>
--------
/* Blood Structure added */
struct blood_structure *blood_list = NULL;      /* global linked list of
rooms with blood in dem! */
struct blood_structure head_blood_list;         /* the first structure
in the blood list        */

in fight.c    <also near the top>
--------
/* External structures */
extern struct blood_structure *blood_list;      /* In db.c - Jus */
extern struct blood_structure head_blood_list;  /* In db.c - Jus */
void increase_room_blood(int room);

<later on, when it gest called when x amount of damage is done on some
victim..>
 increase_room_blood(ch->in_room);

<and at the bottom of the file, the function>
/* This will increase the number of blood units in a room. If the room
has no blood units,
    then a new room will be added to the linked list. */
void increase_room_blood(int room)
{
        bool empty = TRUE;
        struct blood_structure *temp;

        /* Lets find the room. If no struct exsists, then it will create
it next */
        while (temp!= NULL) {
                if (temp->number != room)
                        temp= temp->next;
                else {
                        /* We have the room, so add the info and quit
the while loop */
                        temp->amount +=1;
                        empty = FALSE;
                        temp = temp->next;
                }
        }

        if ((temp == NULL) && (empty == TRUE)){
                CREATE(temp, struct blood_structure, 1);
                temp->number = room;
                temp->amount = 1;
                temp->next = NULL;
        }
}


For some reason, i don't know how to tell the global link (extern'd at
the top), to use the
temp link .. maybe i've gone through this all wrong... *Shrug*
Feedback very welcom. Flames into my recycling bin.

Thank you all...

Jussy


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST