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 »

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 »

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 »

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 »

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 »

YAY !

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

Re: Building strings

Post 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!!!
matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Building strings

Post 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 :)
nolddor
Very interested
Posts: 102
Joined: Sun Jun 02, 2013 1:35 pm
Location: Spain

Re: Building strings

Post by nolddor »

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

EDIT: Done! ;)
Post Reply