Advertisement

Simple C++ Question

Started by January 03, 2000 10:53 PM
3 comments, last by jtecin 24 years, 11 months ago
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
Advertisement
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
Ok, so
lu = unsigned long
d = dword
...

Is there an internet-page with the full list?

Drago
osu!
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)

This topic is closed to new replies.

Advertisement