Last active
August 29, 2015 14:15
-
-
Save nqpz/d61b09ba6baabeb2ca2d to your computer and use it in GitHub Desktop.
This file contains 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
// Only works for constants and arrays, so watch out. | |
#define write(s) syscall_write(1, s, sizeof(s)) | |
void write_char(char c) { | |
syscall_write(1, &c, 1); | |
} | |
void write_int(int n) { | |
int k, leading_zeros, div; | |
if (n == 0) { | |
write_char('0'); | |
return; | |
} | |
if (n < 0) { | |
write("-"); | |
n *= -1; | |
} | |
k = 1000000000; | |
leading_zeros = 1; | |
while (k > 0) { | |
div = n / k; | |
if (leading_zeros && div != 0) { | |
leading_zeros = 0; | |
} | |
if (!leading_zeros) { | |
write_char(div + '0'); | |
} | |
n %= k; | |
k /= 10; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Et systemkald per tegn? Ad