Link to home
Start Free TrialLog in
Avatar of JonMarkGo
JonMarkGo

asked on

Sprintf %s not concatenating

We have a MUD codebase. We did a couple code changes lately and suddenly anywhere sprintf("%s %s",str1, str2) is ends up just showing the second string. If we change the space to a -, it works fine...
Avatar of ozo
ozo
Flag of United States of America image

sprintf is called as
 sprintf(destinationstring,"%s %s",str1, str2)
Avatar of JonMarkGo
JonMarkGo

ASKER

Sorry, typoed the example. Here's a real example: sprintf(updatequery, "%s ip='%s',", updatequery, d->ip);

The string is ending up as just ip='x.x.x.x.', missing the updatequery before it
The sprintf function is equivalent to fprintf, except that the output is written into
an array (specified by the argument s) rather than to a stream. A null character is written
at the end of the characters written; it is not counted as part of the returned value. *If
copying takes place between objects that overlap, the behavior is undefined.*
But it's worked fine up until a couple days ago.
"the behavior is undefined." means that you cannot depend on how it may work on any particular day.
Somehow we got it fixed, not sure how...
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Force accepted.
Vee_Mod
Community Support Moderator