get_next_line/ft_atoi.c

33 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbrochar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/27 19:18:43 by gbrochar #+# #+# */
/* Updated: 2019/02/06 16:16:54 by gbrochar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
long result;
long sign;
result = 0;
while (ft_isspace(*str))
str++;
sign = (*str == '-') ? -1 : 1;
if (*str == '-' || *str == '+')
str++;
while (*str >= '0' && *str <= '9')
{
result = (result * 10) + (*str - '0');
str++;
}
return ((int)(result * sign));
}