Created
April 20, 2018 09:24
-
-
Save ayaderaghul/c398465f88d1feca88d126c2e5424846 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
static int skip_spaces(const char *s, int i) | |
{ | |
while (s[i] == ' ' || (9 <= s[i] && s[i] <= 13) || s[i] == '\n') | |
++i; | |
return (i); | |
} | |
int ft_atoi(const char *str) | |
{ | |
int i; | |
int n; | |
int sign; | |
n = 0; | |
i = 0; | |
sign = 1; | |
i = skip_spaces(str, i); | |
if (str[i] == '+' || str[i] == '-') | |
{ | |
sign = (str[i] == '+') ? 1 : -1; | |
++i; | |
} | |
while ('0' <= str[i] && str[i] <= '9') | |
{ | |
n = n * 10 + (str[i] - '0'); | |
++i; | |
} | |
n = sign * n; | |
return (n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment