I'm using a function that outputs text on the screen, but only accepts a const char*. So I made a function that would take each digit and put it into a char[](called a C style string i think?).
Unfortunately when I did this all it would output seemed to be garbage data(although alot of the characters were the same, so it could be something else)
Could someone help me convert some ints into char[]s?
Here's the function i made:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
char* intToChar(int x)
{
char* y = NULL;
y = newchar[255];
int count = 0;
while(x!=0)
{
y[count] = (char)(x%10);
x /= 10;
count++;
}
return y;
}
Ok I tried what WebJose told me, and it still doesn't seem to work.. All it seems to output are '^' and 'x', and i'm not sure why. Since itoa doesn't seem like a good idea to use, i'm thinking about using stringstreams. But if i put a string where a char[] is supposed to be, would it still work?
edit: Tried the stringstream approach, but it wouldn't take the string. Is there a function to convert string to char[]?