Page 1 of 1

how do you append a string with an integer variable?

PostPosted: Mon Apr 09, 2007 11:57 pm
by Sgt. Sparky
how do you append a string with an integer variable?
or can you just use a "real" variable and set it to get the soucre from &the_variable?

a simple example:
Code: Select all
strcat(display.text, "the variable is set to: ' ");
strcat(display.text, &Number);
strcat(display.text " ' ");

would that work?
Edit: &Number does not work, I did not expect it too really.
what else could I do?
this is the first thing I have been stumped on in a while.
Edit2:
a way to convert an integer or real variable to string would be nice too(that is pretty much what I am asking).

PostPosted: Tue Apr 10, 2007 12:29 am
by makslane
You can use the sprinf function:

Code: Select all
sprintf(display.text, "the variable is set to: %d", Number); //%d for integer, %d for real


More information here:
http://www.cplusplus.com/reference/clib ... rintf.html

PostPosted: Tue Apr 10, 2007 1:59 am
by Sgt. Sparky
thanks :D
I came out with this code so it would fulfill my expectations.
Code: Select all
strcpy(fileText1, display.text);
sprintf(sprintString, "The variavle will be set to '%d'", Number);
strcat(fileText1, sprintString);
strcpy(display.text, fileText1);
strcat(display.text, "\ntype out the g value.\n");

but everytime I do it the game crashes, :(
I think it is a code overload because of a bunch of extra proccessing stuff it is doing in 1/30th of a second(possible?)
to test this I will use another way to proccess it :D
Edit: Nope, still crashes :(
what is the problem?

PostPosted: Tue Apr 10, 2007 2:06 am
by makslane
Hou you create the variables?

PostPosted: Tue Apr 10, 2007 2:42 am
by Sgt. Sparky
variables add string, but the Number is a real variable :D

PostPosted: Tue Apr 10, 2007 3:51 am
by Sgt. Sparky
http://game-editor.com/forum/viewtopic. ... 8351#18351
there is the game :D
it is still in testing stages.

PostPosted: Tue Apr 10, 2007 1:06 pm
by makslane
Use %f instead %d

PostPosted: Tue Apr 10, 2007 9:38 pm
by Sgt. Sparky
:) okay! thanks :D

makslane, watch it!

PostPosted: Wed Apr 11, 2007 6:10 am
by kyensoftware
Makslane, be careful!
That's how you put in a C++ comment! C comments are '.
I just thought that the other n00bs besides me would follow that mistake....

PostPosted: Wed Apr 11, 2007 11:57 pm
by Sgt. Sparky
:)
Game editor has a few C++ codes :D