I've been trying to implement a dynamic link list under the char_player_data
struct to the effect that the character will have a list of character that
that character 'knows'. (so that the character will see names vs. seeing
short descs of other players) This is all related under an 'introduce'
command i put in. When I first declare a temporary pointer to insert into
the linked list (alphabetically) I do a
struct known_char_node *new_rec_ptr;
but when I attempt to allocate the memory, i think i'm encountering a
problem. Nowhere can i find any good documentation on the malloc statement.
I first tried using 'new' but i got undeclared identifier. I assumed that
since its of .c extension. I must resort to the 'C' malloc and free.
I'm currently using this (it compiles correctly but I crash on the specified
line)
void add_friend(struct char_data *ch, struct char_data *victim)
{
struct known_char_node *new_rec_ptr; //Temporary pointer for the new friend
new_rec_ptr = (struct known_char_node *) malloc((sizeof(struct
known_char_node)) + 1); //Allocate Memory
if(new_rec_ptr != NULL) //Allocated memory correctly?
{ //Get data and insert node
/*ERROR*/strcpy(new_rec_ptr->known_char, GET_NAME(ch));// ERROR IS
HERE insert_node(new_rec_ptr, ch, victim);
}
else
log("SYSERR: Memory allocation failed in act.comm.c(600)");
}
I found the crashing line using log statements and frankly- i'm lost
i fooled around with the malloc line, removing the (struct known_char_node
*) part at the reccomendation of a friend and it didn't help at all. If
anyone has any insights to this conglomeration of bad code, please shoot me
a mail. :) thanks
Naeis of DaneuranMUD
_____________________________________________________________________________________
Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com
--
+---------------------------------------------------------------+
| FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
| Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
+---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 04/11/01 PDT