Archived
1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
libft/ft_atoi.c
2023-11-06 11:00:52 +01:00

38 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 09:00:27 by adjoly #+# #+# */
/* Updated: 2023/11/05 15:27:36 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *nptr)
{
int i;
int sign;
int nbr;
i = 0;
sign = 1;
nbr = 0;
while ((nptr[i] >= 7 && nptr[i] <= 13) || nptr[i] == 32)
i++;
if (nptr[i] == '-')
{
sign *= -1;
i++;
}
else if (nptr[i] == '+')
i++;
while (nptr[i] >= '0' && nptr[i] <= '9')
{
nbr = nbr * 10 + (nptr[i] - '0');
i++;
}
return (nbr * sign);
}