Building strings

SGDK only sub forum

Moderator: Stef

Post Reply
matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Building strings

Post by matteus » Wed Sep 16, 2015 2:13 pm

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?

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Building strings

Post by Stef » Wed Sep 16, 2015 6:06 pm

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

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: Building strings

Post by tryphon » Wed Sep 16, 2015 6:57 pm

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 :)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Building strings

Post by Stef » Wed Sep 16, 2015 8:48 pm

Oups.. i committed changes but forgot to "push" them :p You should find them now (as many others changes actually) !

tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: Building strings

Post by tryphon » Wed Sep 16, 2015 9:19 pm

YAY !

Thanks :)

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Building strings

Post by matteus » Wed Sep 16, 2015 9:25 pm

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!!!

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Building strings

Post by matteus » Thu Sep 17, 2015 10:13 am

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 :)

nolddor
Very interested
Posts: 102
Joined: Sun Jun 02, 2013 1:35 pm
Location: Spain

Re: Building strings

Post by nolddor » Thu Sep 17, 2015 2:01 pm

PaspallasDev doesn't read this forum but i'll tell him your message.

EDIT: Done! ;)

Post Reply