Re: sprintf

From: Rick Glover (magik@thegrid.net)
Date: 12/05/98


In lamens terms, they both work, but the first can cause recursion.  It is
easy to mess up the first one.  The second simply tells sprintf() to add
Hello to the position of the pointer, which is buf + strlen(buf).

In the example that you posted, it would be better to use strcat(buf,
"Hello");.  It is faster than sprintf.

If you don't like the length of the code that buf + strlen(buf) produces,
there is a macro in shop.h called END_OF().  Use it like:
sprintf(END_OF(buf), "Hello");  And you may want to move it to utils.h so
that all your files can use it.

Rick

-----Original Message-----
From: I Chose No Name <MUDaholic@aol.com>
To: CIRCLE@post.queensu.ca <CIRCLE@post.queensu.ca>
Date: Saturday, December 05, 1998 1:47 PM
Subject:  sprintf


>Okay, I was just wondering what the difference is between these two lines:
>..
>sprintf(buf, "%sHello", buf);
>sprintf(buf + strlen(buf), "Hello");


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



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