Create a string

Non-platform specific questions.

Create a string

Postby grandeMur87 » Sat Mar 27, 2010 1:56 pm

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?
grandeMur87
 
Posts: 3
Joined: Tue Mar 23, 2010 7:52 pm
Score: 0 Give a positive score

Re: Create a string

Postby skydereign » Sat Mar 27, 2010 7:39 pm

Use sprintf.
Code: Select all
sprintf(lifeString, "%i", intValue);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Create a string

Postby Hblade » Sat Mar 27, 2010 8:48 pm

Skydereign, correct me if I'm wrong... but wont %d give you the same thing? I've never thought of using %i :O
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Create a string

Postby skydereign » Sat Mar 27, 2010 9:28 pm

They differ when using scanf, but for the printfs they are the same.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Create a string

Postby Hblade » Sat Mar 27, 2010 9:34 pm

Ahh, thanks for the info :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron