42_push_swap/ft_atoi.c
Camille Chauvet 3fc423de4a presque
2022-12-06 17:35:45 +01:00

37 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/08 18:27:58 by cchauvet #+# #+# */
/* Updated: 2022/12/02 21:39:08 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
int ft_atoi(char *str)
{
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);
}