Skip to content

Instantly share code, notes, and snippets.

@henix
Created September 11, 2013 18:13
Show Gist options
  • Save henix/6527523 to your computer and use it in GitHub Desktop.
Save henix/6527523 to your computer and use it in GitHub Desktop.
putllong
static inline void putllong(long long n)
{
static char buf[20];
register int pos;
register long long x = n;
if (x == 0) {
putchar('0');
return;
}
if (x == LLONG_MIN) { // x = -x do not work for the minimal value of long long, so process it first
printf("%lld", 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