On Tue, 17 Aug 1999, Angus Mezick wrote: > I have found that SGI Irix 6.2 and Redhat Linux both do not like the > sprintf(buf,"%sblah",buf); syntax, but they are not consistant. > (sometimes it works) > > > > >When you are adding to a buffer before sending it to the > > >character, which is the more suitable method? > > #1 or #3 > > >1) > > >sprintf (buf + strlen(buf), "blah....."); > > >or 2) > > >sprintf(buf, "%sblah......", buf); > > This won't work on Borland C as it clears the target buffer before copying. > > 3) > > int i = 0; > > i += sprintf(buf + i, "blah..."); > > Because further sprintf() calls do not have to recalculate string length, > > you get it for free. From my experience with problems under borland as well as linux where sprintf clears the target buffer before writing to it I tend to use a second buffer. This may be a little less cpu and memory friendly, but in these days of 600mhz cpus and machines with a gig of ram who really cares :) Sterling @ Wyld Knight +------------------------------------------------------------+ | 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