50 lines
1.4 KiB
C
50 lines
1.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_atoi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/05/22 12:44:41 by sadjigui #+# #+# */
|
|
/* Updated: 2021/12/08 19:13:51 by sadjigui ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
static int ft_space(const char *str)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
while ((str[i] == 32) || (str[i] >= 9 && str[i] <= 13))
|
|
i++;
|
|
return (i);
|
|
}
|
|
|
|
long ft_atoi(const char *str)
|
|
{
|
|
int i;
|
|
int sign;
|
|
long result;
|
|
|
|
result = 0;
|
|
i = ft_space(str);
|
|
sign = 0;
|
|
if (str[i] == '-' || str[i] == '+')
|
|
{
|
|
if (str[i] == '-')
|
|
sign = 1;
|
|
i++;
|
|
}
|
|
while (str[i] >= '0' && str[i] <= '9')
|
|
{
|
|
result = result * 10 + str[i] - 48;
|
|
i++;
|
|
}
|
|
if (sign == 1)
|
|
return (-result);
|
|
else
|
|
return (result);
|
|
}
|