how do you append a string with an integer variable?

Non-platform specific questions.

how do you append a string with an integer variable?

Postby Sgt. Sparky » Mon Apr 09, 2007 11:57 pm

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).
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby makslane » Tue Apr 10, 2007 12:29 am

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
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Sgt. Sparky » Tue Apr 10, 2007 1:59 am

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?
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby makslane » Tue Apr 10, 2007 2:06 am

Hou you create the variables?
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Sgt. Sparky » Tue Apr 10, 2007 2:42 am

variables add string, but the Number is a real variable :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Sgt. Sparky » Tue Apr 10, 2007 3:51 am

http://game-editor.com/forum/viewtopic. ... 8351#18351
there is the game :D
it is still in testing stages.
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby makslane » Tue Apr 10, 2007 1:06 pm

Use %f instead %d
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Sgt. Sparky » Tue Apr 10, 2007 9:38 pm

:) okay! thanks :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

makslane, watch it!

Postby kyensoftware » Wed Apr 11, 2007 6:10 am

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....
User avatar
kyensoftware
 
Posts: 198
Joined: Thu Oct 26, 2006 7:49 am
Score: 5 Give a positive score

Postby Sgt. Sparky » Wed Apr 11, 2007 11:57 pm

:)
Game editor has a few C++ codes :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest