Skip to content

Instantly share code, notes, and snippets.

@BlockoS
Created December 28, 2011 18:46
Show Gist options
  • Save BlockoS/1529130 to your computer and use it in GitHub Desktop.
Save BlockoS/1529130 to your computer and use it in GitHub Desktop.
itoa base 10
inline int Stringify(int value, char* buffer, int bufferLen)
{
int i = bufferLen-1, tmp;
char *ptr = buffer, c;
for(; value && i; --i)
{
tmp = value;
value/=10;
*ptr++ = "9876543210123456789"[9 + tmp - value*10];
}
if((tmp < 0) && i)
{
*ptr++ = '-';
--i;
}
if(i) *ptr-- = '\0';
tmp = ptr - buffer;
while(buffer < ptr)
{
c = *ptr;
*ptr-- = *buffer;
*buffer++ = c;
}
return tmp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment