Re: [Circle] do_who help

From: Professor Hoopster (hoopy@notfoo.res.cmu.edu)
Date: 08/15/96


On Wed, 14 Aug 1996 goamkows@kirk.geog.sc.edu wrote:
> i've added an elemental to the character file
> ch->player_specials->saved.prefix
> where *prefix is of type char.
> 
> i want to prepend the prefix to the characters name when someone does
> a who, so in do_who, i put in:
> 
>   char *tmp;
> 
> then later on put in 
>   tmp = strcat((wch->player_specials->saved.prefix), (GET_NAME(wch)));

This is no good, unless prefix is big enough to store the player's entire 
name, the prefix, and a null. What you probably mean is:
    char *tmp;
    CREATE(tmp, char, 
      strlen(GET_NAME(wch))+strlen(wch->player_specials->saved.prefix));
    strcpy(tmp, wch->player_specials->saved.prefix);
    strcat(tmp, GET_NAME(wch));

  I hope it's evident to you how completely and utterly inefficient this 
code is, but I'm just trying to show you the corrected version of your 
own code. To do it efficiently....just use one of the pre-allocated 
buffers, and put in a strcpy and strcat. Or where it has a %s for 
GET_NAME, just put in another %s and put in the prefix in the parameter 
list. There are tons of ways of doing this correctly.

> and replaced the GET_NAME in the sprintf that displays the name with tmp.
> 
> it compiles without warning or error, but when i go to do a who, it
> crashes the mud.  

Yeah, I can imagine.

> gdb is giving the value of blah->saved.prefix as what i want it to be,
> and presumably GET_NAME(wch) will turn up the appropriate name string,
> so i have no idea what i am doing wrong :(

You're abusing C. :P
+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



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