Skip to content

Instantly share code, notes, and snippets.

@madex
Created October 20, 2014 09:54
Show Gist options
  • Select an option

  • Save madex/027febb4f8747670f6d0 to your computer and use it in GitHub Desktop.

Select an option

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.
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