Skip to content

Commit

Permalink
Update ft_atoi.c
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-br authored Jun 18, 2022
1 parent 45ad7cf commit 30fc9b2
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions part_1/ft_atoi.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,12 @@ int ft_atoi(const char *nptr)
int signal;
int result;

signal = 1;
result = 0;
while ((*nptr >= 9 && *nptr <= 13) || (*nptr == ' '))
nptr++;
if (*nptr == '-' || *nptr == '+')
{
if (*nptr == '-')
signal = -1;
nptr++;
}
signal = ((ft_isdigit(*nptr) || *nptr == '+') - (*nptr == '-'));
nptr += (*nptr == '-' || *nptr == '+');
while (ft_isdigit(*nptr))
{
result = result * 10 + (*nptr - '0');
nptr++;
}
if (result == 0)
return (0);
result = result * 10 + (*nptr++ - '0');
return (result * signal);
}

0 comments on commit 30fc9b2

Please sign in to comment.