Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Android / Converting int to string without itoa to use with AGK Text object?

Author
Message
PaulTR
6
Years of Service
User Offline
Joined: 25th Oct 2012
Location: Fresno, CA
Posted: 16th Nov 2012 19:58
I'm trying to create a text object that uses an integer to set the text. Formally I used these lines:

score += 100;
agk::SetTextString(scoreDisplayText, itoa(score, tempNum, 10));

where tempNum is a char array and score is an int, but now that I'm running it with the Android NDK, it seems itoa doesn't work. Any suggestions?
Ancient Lady
Valued Member
15
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 16th Nov 2012 20:17
Try using sprintf. Something like this:


This is compatible on all platforms.

Cheers,
Ancient Lady
AGK Community Tester
PaulTR
6
Years of Service
User Offline
Joined: 25th Oct 2012
Location: Fresno, CA
Posted: 16th Nov 2012 20:39
That did the trick. Thank you!
Ancient Lady
Valued Member
15
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 16th Nov 2012 21:11
Glad to help.

You can create your own set of functions to format strings the way you want. This is an example of a how do your own formatted strings:


The 'vsnprintf' version makes sure that the formatting doesn't overflow the buffer.

In your code, you would then do:


Cheers,
Ancient Lady
AGK Community Tester

Login to post a reply

Server time is: 2019-06-25 16:34:16
Your offset time is: 2019-06-25 16:34:16