37 lines
1.2 KiB
C
37 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_atoi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tchivert <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/04/08 15:27:15 by tchivert #+# #+# */
|
|
/* Updated: 2019/09/04 05:13:26 by tchivert ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
int ft_atoi(const char *str)
|
|
{
|
|
int nb;
|
|
int i;
|
|
int neg;
|
|
|
|
nb = 0;
|
|
i = 0;
|
|
neg = 1;
|
|
while ((str[i] >= 9 && str[i] <= 13) || str[i] == ' ')
|
|
i++;
|
|
if (str[i] == '-')
|
|
{
|
|
neg = -1;
|
|
i++;
|
|
}
|
|
else if (str[i] == '+')
|
|
i++;
|
|
while (str[i] && ft_isdigit(str[i]) == 1)
|
|
nb = nb * 10 + str[i++] - 48;
|
|
return (neg * nb);
|
|
}
|