🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Simple C++ Question
Gosh I can''t believe I forgot the syntax for how to do this in C++. Anyway, to my question. I have a Player''s health that I want to print to the screen that is an int. However, my function for drawing GDI text only takes char*. How the heck would I convert this or whatever so I could print the number? Would I use sprintf, strcat, or what? Thanks for any replies in advance.
Easiest way would be wsprintf (seeing as you almost certainly have windows.h included)
char Health[4]; // Guessing max_health will be <999
wsprintf("%lu/0", Player.Health);
This assumes Player.Health is an unsigned long representing the players health. At the end Health will be a null terminated string containing your players health.
HTH
Steven Vallis
char Health[4]; // Guessing max_health will be <999
wsprintf("%lu/0", Player.Health);
This assumes Player.Health is an unsigned long representing the players health. At the end Health will be a null terminated string containing your players health.
HTH
Steven Vallis
Or just for kicks for non ansi windows only code try integer to alpha like so:
itoa(const char* buffer, uint num, uint base)
char mystring[10] = "";
so itoa(mystring, 122, 10);
base 10 == decimal
base 2 == binary
base 16 == hexidecimal
itoa(const char* buffer, uint num, uint base)
char mystring[10] = "";
so itoa(mystring, 122, 10);
base 10 == decimal
base 2 == binary
base 16 == hexidecimal
DWORDs are unsigned longs
The full list is in the VC++5 help, and should be with any compiler help (just search under sprintf as that is part of the core C++ libraries)
The full list is in the VC++5 help, and should be with any compiler help (just search under sprintf as that is part of the core C++ libraries)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement