I'm looking for a way to convert an int to a char*. For instance, I have the number 3, and I want to convert that into a char* "3". I tried this but it doesnt work:
Code:int i = 4; char* c = (char*)i;
I'm looking for a way to convert an int to a char*. For instance, I have the number 3, and I want to convert that into a char* "3". I tried this but it doesnt work:
Code:int i = 4; char* c = (char*)i;
Well, the code you have posted does what you told it to do - which is to convert an integer to a char pointer. c will be a pointer pointing to address 4.
But what you conceptually seem to want to do is to convert an integer to a string, which is a different thing. I tend to use sprintf() for that purpose. The language C in itself has no functionality to do what you want, you DO need to call a function of some sort. itoa() is another function that CAN do this, but it's not a standard function.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.