Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Prairie

Int to char array conversion - any suggestions

This topic is 6700 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

simple question here how can I convert: int Integer = 64; into char String[3] = "64"; Im trying to set up a stats shower for my game. I wrote a custom font engine which only accepts character arrays. I''ve tried it with numbers as its fields, so I know that that part of it will work. I just need to convert the integer that my fps function generates into a character array. thanks; Prairie

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Use typecasting..

(char *) integer;

Share this post


Link to post
Share on other sites
Use sprintf, like so:


int Integer = 64;
char String[10];
sprintf(String,"%i",Integer);


Share this post


Link to post
Share on other sites
Morbo is right... that will work...

Optionally, you could use itoa()...

    
itoa(Integer, String, 10);


that last parameter tells itoa what base to use... 2 for binary, 10 for decimal, 16 for hex, etc.

remember to include stdlib.h if you're gonna use it tho!


~Morkhai



Edited by - Morkhai on July 18, 2000 12:40:13 PM

Share this post


Link to post
Share on other sites
thanks Morkhai, it worked like a charm. I tried all of the above suggestions and that was the only one that worked. It worked and thats all that matters, so thanks again.

-Prairie


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!