Created
October 20, 2014 09:54
-
-
Save madex/027febb4f8747670f6d0 to your computer and use it in GitHub Desktop.
small converter for string decimal numbers integers for microcontoller. Numbers can be negeative and starting spaces are ignored.
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
| int atoi(const char *c) { | |
| int result = 0; | |
| int sign = 1; | |
| if (!c) | |
| return 0; | |
| while (*c == ' ') | |
| c++; | |
| if (*c == '-') { | |
| sign = -1; | |
| c++; | |
| } | |
| while (*c >= '0' && *c <= '9') { | |
| result *= 10; | |
| result += *c++ - '0'; | |
| } | |
| return result * sign; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment