Int to char array conversion - any suggestions

Started by
4 comments, last by Prairie 23 years, 9 months ago
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
Advertisement
Use typecasting..

(char *) integer;
Use typecasting..

(char *) integer;
Use sprintf, like so:

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


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
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


This topic is closed to new replies.

Advertisement