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 / Outputing doubles and other number data types with dbText?

Author
Message
Stucky
15
Years of Service
User Offline
Joined: 11th Apr 2009
Location:
Posted: 9th May 2009 11:05
Its always bugged me how dbText uses char* as a string, its just a huge pain in the ass if you want to output numbers. After looking around I found this thread here, so I already know you can convert integers into a char* to be used in dbText, but what I need is a way to output doubles and floats using dbText.

Thanks
go2none
15
Years of Service
User Offline
Joined: 8th Oct 2008
Location: London
Posted: 9th May 2009 12:34
You can output int and float using dbText and dbStr.

or you can try:

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 9th May 2009 17:49 Edited at: 9th May 2009 17:50
Quote: "Its always bugged me how dbText uses char* as a string"


I'm not sure how you'd want it otherwise. The name of the function is dbText. Yes, the function could be overloaded but there are a number of alternatives. You can always write your own overloaded functions.


If you're restricting your coding to the functions provided by Dark GDK then you're doing yourself a big disfavor. The C++ standard library has quite a number of conversion functions and when it all comes down to it, there's always sprintf() to format your output. It behooves you to learn at least what functions are available even if you don't memorize their footprint. You'll know you can look them up when you have need and won't need to re-invent functions.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Stucky
15
Years of Service
User Offline
Joined: 11th Apr 2009
Location:
Posted: 10th May 2009 04:31
That worked, thanks for the help. I've never actually used sprintf before, because it looked so similar to printf I used you needed to use it in a console application so I didn't look into it.

Lilith, I am using other c libraries. I'm creating a solar system simulation so cmath and ctime are pretty much a must. Also using string of course, I just never knew sprintf was capable of turning number data types into char *.

Thanks for the help guys!
DnB
15
Years of Service
User Offline
Joined: 28th Feb 2009
Location:
Posted: 12th May 2009 20:09
Yea, I had the same problem with dbText when I was trying to display numbers. It is annoying. Although try this


Its simple and it works for me.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 13th May 2009 07:58
And it also causes memory leaks with that code alone, stick with sprintf.

Login to post a reply

Server time is: 2024-10-01 01:27:35
Your offset time is: 2024-10-01 01:27:35