Created
September 11, 2013 07:40
-
-
Save henix/6520411 to your computer and use it in GitHub Desktop.
putint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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