Created
February 2, 2016 12:59
-
-
Save niorko/6f150c86d1f9db7ef4b4 to your computer and use it in GitHub Desktop.
Alternative to sprintf for pebble SDK (no need for stdio.h)
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
| char *itoa(int num) | |
| { | |
| static char buff[20] = {}; | |
| int i = 0, temp_num = num, length = 0; | |
| char *string = buff; | |
| if (num >= 0) { | |
| while(temp_num) { | |
| temp_num /= 10; | |
| length++; | |
| } | |
| for (i = 0; i < length; i++) { | |
| buff[(length-1)-i] = '0' + (num % 10); | |
| num /= 10; | |
| } | |
| buff[i] = '\0'; // can't forget the null byte to properly end our string | |
| } | |
| else { | |
| return "Unsupported Number"; | |
| } | |
| return string; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment