Page 1 of 1

Building strings

Posted: Wed Sep 16, 2015 2:13 pm
by matteus
I was wondering if there was a nicer way in C of carrying out this:

Code: Select all

char static YouHaveStr[] = "You have ";
char static Stakes1Str[] = " stakes";

// Builds char "You have X stakes"
strclr(StakesStr); // clear stakes char
intToStr(StakesInt, StakesStr, 0); // convert stakes int to char
strclr(MessageBoxLineStr2);  // clear char
strcpy(MessageBoxLineStr2, YouHaveStr); // copy "You have "
strcat(MessageBoxLineStr2, StakesStr); // copy no of stakes to string
strcat(MessageBoxLineStr2, Stakes1Str); // copy " stakes"
I could use snprintf. I'm guessing it would need to be written in strings.h?

Re: Building strings

Posted: Wed Sep 16, 2015 6:06 pm
by Stef
Thanks to PaspallasDev and JackNolddor the next SGDK version will include the very useful sprintf(...) method which make thing so much easier for string operation. If you are impatient you can get the latest string.c / string.h files from the Github repository : https://github.com/Stephane-D/SGDK

Re: Building strings

Posted: Wed Sep 16, 2015 6:57 pm
by tryphon
I don't find it :)

I've looked some days ago about it and didn't find, so I was surprised by your message. I made another search right now and didn't find it either. I was about to code my own version :)

Re: Building strings

Posted: Wed Sep 16, 2015 8:48 pm
by Stef
Oups.. i committed changes but forgot to "push" them :p You should find them now (as many others changes actually) !

Re: Building strings

Posted: Wed Sep 16, 2015 9:19 pm
by tryphon
YAY !

Thanks :)

Re: Building strings

Posted: Wed Sep 16, 2015 9:25 pm
by matteus
Stef wrote:Thanks to PaspallasDev and JackNolddor the next SGDK version will include the very useful sprintf(...) method which make thing so much easier for string operation. If you are impatient you can get the latest string.c / string.h files from the Github repository : https://github.com/Stephane-D/SGDK
Oh fantastic!!!

Re: Building strings

Posted: Thu Sep 17, 2015 10:13 am
by matteus
I'm not sure if aspallasDev and JackNolddor read this forum much but can you thank them for me Stef?

The number of temp char arrays, intToStr, StrCat and StrCpy calls they've saved me is immense!

Extremely happy :)

Re: Building strings

Posted: Thu Sep 17, 2015 2:01 pm
by nolddor
PaspallasDev doesn't read this forum but i'll tell him your message.

EDIT: Done! ;)