There are a few things wrong with your logic:
- The variable
size
is used by never initialized. I would guess it should be initialized to zero and then incremented in the while loop with the ++ operator.
- Also in the while loop,
temp
should probably be set with the /= operator.
- Another thing is the
str
pointer appears to be set using the comparison operator instead of the assignment operator which is a single equals sign.
Here is what your logic looks like with these changes :
void ToString( char* str, int number )
{
int i;
int size = 0;
int temp = number;
while( temp != 0 )
{
temp /= 10;
++size;
}
for( int i = size - 1; i >= 0; --i )
{
*str = ( number / 10 ) + '0';
str++;
}
It's still not right but at least the syntax errors have been fixed. I recommend that you run your program in a debugger so you can see what is going on with it. At the very least, add some output statements so you can see the characters as they are added to the string.