sprintf issues
Posted: Sun Sep 10, 2017 9:42 am
I gather there are problems with sprintf? I wondered what the alternative way to do this would be? strcpy?
Sega Megadrive/Genesis development
http://gendev.spritesmind.net/forum/
http://gendev.spritesmind.net/forum/viewtopic.php?f=19&t=2708
Yeah I was doing all the conversion process before and then I learnt that sprintf was now supported. From what I gather though sprintf in the SGDK is buggy? Stef mentioned to me that it's not perfect.Sik wrote: ↑Sun Sep 10, 2017 10:45 amUm, what? o_O Kind of hard to even discuss if you don't even say what's wrong with sprintf.
Also: all strcpy does is copy a string, while sprintf does a tad more (like converting numbers into strings, aligning text, etc.). Also sprintf is useful if you're concatenating more than two strings, or possibly even when it's just two (e.g. storing into a new string - let's just say that strcat is pretty crappy since it needs to scan all the original string before inserting the new one, no real advantage to doing strlen+strcpy and you may have taken the length from elsewhere already).
I'm just unsure what my alternative is given strcat is crappy// build string "You need X stakes"
strclr(MessageBoxLineStr1);
sprintf(MessageBoxLineStr1, "%s%d%s", YouNeedStr, StalksRequiredInt, Stakes1Str);
// build string "You have X stakes"
strclr(MessageBoxLineStr2);
sprintf(MessageBoxLineStr2, "%s%d%s", YouHaveStr, StakesInt, Stakes1Str);