Re: Writing over the end of a string

From: Daniel A. Koepke (dkoepke@california.com)
Date: 09/09/99


Today, Ron Hensley spake to the list:

> That looks fine. Also you will more then likely see this sort of thing
> done in the Circle code with
>   sprintf(buf,"some text");
>   sprintf(buf, "%smore text",buf);

Hopefully not.  That code is erroneous and unportable.

Anyway, if you're simply wanting to copy over the last character (be it an
'\n' or something else entirely) with a new string:

    strcpy(buf + (strlen(buf) - 1), "...");

or the equivalent using sprintf().

-dak : Yes, I do mean strcpy() and not strcat().


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



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