Re: problem manipulating strings

From: Pink Floyd (
Date: 08/02/95

   >> void set_title(struct char_data * ch, char *title)
   >> {
   >>   if (title == NULL) {
   >>     title = READ_TITLE(ch);
   >>     if ((GET_CLASS(ch) == CLASS_PALADIN) && (GET_LEVEL(ch) == 10)
   >>      /* this next line causes the Segmentation fault */
   >>       strcat(title, "some string");
   >i'm not a "rocket scientist" at C but i dont think strcat will work for 
   >this. if the pointer is null (there is no data inteh string) then you 
   >cant ADD to it. you would want to use:
   >   strcpy(title, "some string");
   >and then if you want to append to title, use strcat
First of all, yes, the parentheses are screwed on the 5th line (only in
 my example, though, not in the source). But, I am not trying to strcat to 
a null string, I don't think...  title has the value READ_TITLE(ch) if you 
look a little more closely.  It already has a string, and I don't think the 
length of title is formally declared, but when this gets called in the
advance() function, the *title arg is passed as NULL.  There is no prob. with
assigning title a value of length strlen(READ_TITLE(ch)), so why is there
a prob. adding an extra "some string" on to it??
Thanks for the help...

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