Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / C++ Int Varible to a String

Author
Message
Timidon
19
Years of Service
User Offline
Joined: 26th Jun 2005
Location: Bakersfield, Ca. USA.
Posted: 23rd Mar 2006 07:59
I forgot how unforgiving strings are in C.

I am curious does the DGSDK have any (Int, Float) to Strings commands. I am looking for something similar so that I can display some debug text. I need to convert a number to a string for the dbText function. I am not entirely new to C,

does anybody have a function handy?

There are many answers but just one question" ~ Jerilith the Mad
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 23rd Mar 2006 09:03
Why not use sprintf ? Or perhaps dbStr ?

Timidon
19
Years of Service
User Offline
Joined: 26th Jun 2005
Location: Bakersfield, Ca. USA.
Posted: 23rd Mar 2006 09:19
whats dbStr? hmmm I thats I may be needing...

the command dbStr$() dose not work, but dbStr() does! I just spent hours looking for this thanks!

Another squish!

Thank you

There are many answers but just one question" ~ Jerilith the Mad
Denaje
19
Years of Service
User Offline
Joined: 5th Feb 2005
Location:
Posted: 28th Mar 2006 04:40
If you're like me, then you might not like using Dark Basic commands (to save CPU possibly). To convert ints or floats to strings in just plain C++, do this:

Declare a function called toString(float num) or something, be sure to include <sstream>, <string.h>, and <stdlib.h>, and be sure to say "using namespace std" (see the attached code)

Then you can call toString(123) and it returns a C++ style string representation of your number.

To make it output in DarkBasic (as with the print command):

dbPrint((char *) toString(123).c_str());
Denaje
19
Years of Service
User Offline
Joined: 5th Feb 2005
Location:
Posted: 28th Mar 2006 22:01
ONCE AGAIN, here is the toString function I was talking about:

re faze
20
Years of Service
User Offline
Joined: 24th Sep 2004
Location: The shores of hell.
Posted: 29th Mar 2006 01:25
Denaje
19
Years of Service
User Offline
Joined: 5th Feb 2005
Location:
Posted: 29th Mar 2006 01:43
You'd have to use itoa (Int TO Array), not atoi. To do that, you have to do something like this that stores the result into buff, which is a C-style string, NOT a C++ string, so don't get the two confused:

Timidon
19
Years of Service
User Offline
Joined: 26th Jun 2005
Location: Bakersfield, Ca. USA.
Posted: 29th Mar 2006 10:03
Thanks guys that's very helpful!

There are many answers but just one question" ~ Jerilith the Mad

Login to post a reply

Server time is: 2024-11-19 05:25:43
Your offset time is: 2024-11-19 05:25:43