Created
February 2, 2012 05:36
-
-
Save stormbrew/1721726 to your computer and use it in GitHub Desktop.
This file contains 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
#include <stdio.h> | |
int my_atoi(const char *str) | |
{ | |
int neg = 1; | |
int x = 0; | |
if (*str == '-') | |
{ | |
neg = -1; | |
*str++; | |
} | |
while (*str >= '0' && *str <= '9') | |
{ | |
x *= 10; | |
x += *str++ - '0'; | |
} | |
return neg * x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment