C/C++ Int To Char*
I understand some fundamental problems with this conversion (int == 16 bits, char == 8) but what I need is some way to convert an int into a char*. I have a function that'll print a char* string into OpenGL and I have an int framerate. I would like to somehow use this function to display my framerate over my OpenGL drawings. Any ideas?
What you need to do is *format* the int into a character buffer.
Try something like:
Try something like:
Code:
const int MAX_SIZE = 255;
char buf[MAX_SIZE];
snprintf( buf, MAX_SIZE, "FPS: %d", myFps );
//now, pass "buf" to your print function
sprintf or snprintf... see the man pages 
also, on Mac OS X, an int is 32 bits

also, on Mac OS X, an int is 32 bits
Oops on the bit part. I never could remember how many bits went into each different type.
Thanks for the tips. I didn't think of that at all. Hence why I am the beginner and you all are the teachers (though my post count is un-godly huge
).
Thanks for the tips. I didn't think of that at all. Hence why I am the beginner and you all are the teachers (though my post count is un-godly huge
).
Or itoa() and various flavours will do the trick seeing that sprintf does a crap load of other stuff as well.
(Currently on a windows machine so I don't know if the underscore is required.)
Code:
int ival = 10
char sval[20];
_itoa(ival, sval, 10);(Currently on a windows machine so I don't know if the underscore is required.)
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| converting text input to a c char | NelsonMandella | 6 | 3,523 |
Feb 4, 2010 10:58 AM Last Post: NelsonMandella |
|
| (unsigned) char, bitsets when using - + / * | wyrmmage | 7 | 4,160 |
Jul 21, 2007 04:01 PM Last Post: wyrmmage |
|
| Char* to double, int, and back | wyrmmage | 18 | 6,104 |
Jun 24, 2007 11:09 AM Last Post: akb825 |
|
| Return char if input is char, else - int? | Achithyn | 2 | 2,596 |
Aug 6, 2006 03:43 AM Last Post: backslash |
|

