You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

39 lines
1.2 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emartine <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/02 23:14:46 by emartine #+# #+# */
/* Updated: 2017/08/02 23:24:20 by emartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int r;
int minus;
r = 0;
minus = 0;
while (ft_isspace(*str))
str++;
if (*str == '+')
str++;
else if (*str == '-')
{
minus = 1;
str++;
}
while (*str >= '0' && *str <= '9')
{
r = r * 10 + *str - '0';
str++;
}
if (minus)
r = -r;
return (r);
}