Skip to content

Instantly share code, notes, and snippets.

@henix
Created September 11, 2013 07:40
Show Gist options
  • Save henix/6520411 to your computer and use it in GitHub Desktop.
Save henix/6520411 to your computer and use it in GitHub Desktop.
putint
inline void putint(int n)
{
static char buf[20];
register int pos;
register int x = n;
if (x == 0) {
putchar('0');
return;
}
if (x == INT_MIN) { // x = -x do not work for the minimal value of int, so process it first
printf("%d", x);
}
if (x < 0) {
putchar('-');
x = -x;
}
pos = 0;
while (x > 0) {
buf[pos] = x % 10 + '0';
x /= 10;
pos++;
}
pos--;
while (pos >= 0) {
putchar(buf[pos]);
pos--;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment