Created
January 27, 2021 18:26
-
-
Save hrlou/c324252ed9aaf8fc17bdc4f1e2fc51e2 to your computer and use it in GitHub Desktop.
int to char*
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
/* taken from http://www.strudel.org.uk/itoa/ | |
cannot handle negative numbers */ | |
char* itoa(int val, int base){ | |
static char buf[32] = {0}; | |
int i = 30; | |
for(; val && i ; --i, val /= base) | |
buf[i] = "0123456789abcdef"[val % base]; | |
return &buf[i+1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment