Skip to content

Instantly share code, notes, and snippets.

@hrlou
Created January 27, 2021 18:26
Show Gist options
  • Save hrlou/c324252ed9aaf8fc17bdc4f1e2fc51e2 to your computer and use it in GitHub Desktop.
Save hrlou/c324252ed9aaf8fc17bdc4f1e2fc51e2 to your computer and use it in GitHub Desktop.
int to char*
/* 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