On Sat, 13 Dec 1997, Kingmundi wrote: > there is something strange about the way borland c++ 5.01 handles sprintf, > where it will not concatenate two strings together, and so only shows the > last string that was attempted, i verified this by putting > > sprintf(buf, "%s %s ", buf, dirs[door]); > send_to_char(buf, ch); The above code produces undefined results. You have no guarantee that sprintf will read its arguments before it starts doing something to the output buffer. In theory, the compiler writer is allowed to blow up your computer when encountering such code. Unfortunately, few choose to do so :) You must use something like: sprintf(buf+strlen(buf), " %s ", dirs[door]); which will print to the buffer at the place where the output you wish to preserve ends, so it adds to it. For better performance, observe that sprintf() returns the number of characters printed, so you could do something like: char buf[something]; char *pc = buf; ... some loop ... pc += sprintf(pc, " %s ", dirs[door]); which will print to the current place that pc points at (that starts at the beginning of the buffer) and then advance the pointer as many places as characters printed. This may not work on pre-ANSI compilers (Very old Sun machines machines are the only ones still widely available I think). ============================================================================= Erwin Andreasen Herlev, Denmark <erwin@pip.dknet.dk> UNIX System Programmer <URL:http://www.abandoned.org/drylock/> <*> (not speaking for) DDE ============================================================================= +------------------------------------------------------------+ | 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/08/00 PST