Page 1 of 1

Create a string

PostPosted: Sat Mar 27, 2010 1:56 pm
by grandeMur87
Hi,
I have to create a string from an integer variable that represent the life of the character. How can I write the string starting from an integer?

Re: Create a string

PostPosted: Sat Mar 27, 2010 7:39 pm
by skydereign
Use sprintf.
Code: Select all
sprintf(lifeString, "%i", intValue);

Re: Create a string

PostPosted: Sat Mar 27, 2010 8:48 pm
by Hblade
Skydereign, correct me if I'm wrong... but wont %d give you the same thing? I've never thought of using %i :O

Re: Create a string

PostPosted: Sat Mar 27, 2010 9:28 pm
by skydereign
They differ when using scanf, but for the printfs they are the same.

Re: Create a string

PostPosted: Sat Mar 27, 2010 9:34 pm
by Hblade
Ahh, thanks for the info :D