Skip to content

Instantly share code, notes, and snippets.

@ayaderaghul
Created April 20, 2018 09:24
Show Gist options
  • Save ayaderaghul/c398465f88d1feca88d126c2e5424846 to your computer and use it in GitHub Desktop.
Save ayaderaghul/c398465f88d1feca88d126c2e5424846 to your computer and use it in GitHub Desktop.
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