42_push_swap/ft_atoi.c
Camille Chauvet 32be727085 c fini bro
2022-12-11 17:56:20 +01:00

37 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/08 18:27:58 by cchauvet #+# #+# */
/* Updated: 2022/12/11 17:41:54 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
long int ft_atoi(char *str)
{
long int nb;
int i;
int sign;
i = 0;
sign = 1;
nb = 0;
while (str[i] == '+' || str[i] == '-')
{
if (str[i] == '-')
sign *= -1;
i++;
}
while (str[i] != '\0')
{
nb = nb * 10 + str[i] - '0';
i++;
}
return (nb * sign);
}