libftx/libft/ft_atoi.c
Camille Chauvet 3256ce67f7 kekw
2022-12-22 17:57:19 +01:00

40 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/27 16:14:34 by cchauvet #+# #+# */
/* Updated: 2022/09/28 18:15:04 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nptr)
{
char *str;
int out;
int sign;
str = (char *) nptr;
out = 0;
while (*str == ' ' || *str == '\f' || *str == '\v' || *str == '\t'
|| *str == '\r' || *str == '\n')
str++;
sign = 1;
if (*str == '-' || *str == '+')
{
if (*str == '-')
sign = -1;
str++;
}
while (ft_isdigit(*str))
{
out = 10 * out + *str - 48;
str++;
}
return (out * sign);
}