Game Development Community

Can somone explain dsprintf?

by Nathan Bowhay - ESAL · in Torque Game Engine · 10/03/2006 (2:37 pm) · 6 replies

I am trying to figure out the syntax for dsprintf right now it would be really usefull for the current project.

I am trying to convert from a const cha*, that was returned from script (Con::exicutef(...)), to bool or in.

Any ideas?

Thanks in advance...

#1
10/03/2006 (3:00 pm)
You use dAtoi/dAtob/dAtof for that.

Besides, you can get the syntax to dSprintf all over the source.
#2
10/03/2006 (9:23 pm)
Thank you for this help I will look into dAtoi...

One of my friends and co-workers on this project mention that you can you dsprintf even though it wasn't created for this, but it is a bit tricky in using it. I talk to him tonight and he explained how to use it. I ended up just using strings.h and strcmp, but this is not going to be a permanent solution since it is windows specific.

I will definitely look into dAtob... , especially if it is not machine specific. It isn't is it?
#3
10/03/2006 (9:46 pm)
Nathan -

it's a bit unclear exactly what you want here.

you have a const char* which is along the lines of "0", "1" or some other number like "123",
and you want to convert it to a boolean or an int ?

if so, dSprintf cannot be used.

you want to use what stefan recommended: dAtob for bools, or dAtoi for ints.

eg:
S32 myInt = dAtoi("123");
(S32 is the torque version of int)

if however you want to go the other direction,
ie from an int to a string,
then yes, dSprintf is your boy,
and you would use it thus:
char buf[100];
dSprintf(buf, 100, "%d", myInt);


- 100 is obviously way more than you need,
and to understand the "%d", consult google for "sprintf".
#4
10/04/2006 (7:42 am)
Oh now it makes why more sense! Thank you so much this is very helpful!

I will use bool myBool = dAtob(myChar);

My friend must have gotten mixed up. I am also very glad to now understand what dSprintf does.

Thank you all. And a big thanks to Orion Elenzil for explaining everything. That is what I was looking for.
#5
10/04/2006 (7:46 am)
Glad it worked out !
#6
10/04/2006 (11:32 am)
I suspect your friend pointed you [or should have...] at dSscanf, not dSprintf.

sscanf is very powerful but honestly if all you have is a string containing a decimal number, then you should stick with dAtoi or dAtob.

Gary (-;