Problems with Linked Lists

From: Rasdan (rasdan@PEAK.ORG)
Date: 09/25/97

Hey all,

I have a rather bad problem. I have just made my first real attempt at
creating a linked list, and am having problems adding an entry to it.

What happens when an entry is added, is that all previous entries are
over-written with the new entry, but then only the names themselves are
over-written, everything that is an integer remains the same.

So, I have done this:

struct player_index_element {
  char *name;
  int id;

  struct player_index_element *next;

Then basically, did this:

void load_player_index(void)
  struct player_index_element pie;

  /* Open file stuff here -- This part is easy */

  while (fscanf(index, "%s %s", name, idnum) != EOF) {
    if ( {
      free (; = NULL;
    } = str_dup(name); = atoi(idnum);

void create_pfile_entry(struct player_index_element *pie)
  struct player_index_element *pindex;

  pie->next = NULL;

  CREATE(pindex, struct player_index_element, 1);

  *pindex = *pie;

  pindex->next = player_table;
  player_table = pindex;

I have done extensive logs on it to track the problem down to where the
comment is, but I can go no further.

pindex->id copies over okay onto player_table, but all the names become
the last name on the list.

If any of you can help, I will forever be in your debt. :)


  I have done so much,
  with so little,                         James C. Thomas Jr.
  for so long,                                  Rasdan
  That I can do anything                Head Coder of Finality!
  with nothing.
      Finality is based upon CircleMUD 3.0, check us out:

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

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