42_push_swap/ft_atoi.c

37 lines
1.2 KiB
C
Raw Permalink Normal View History

2022-11-23 15:44:27 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/08 18:27:58 by cchauvet #+# #+# */
2022-12-11 11:56:20 -05:00
/* Updated: 2022/12/11 17:41:54 by cchauvet ### ########.fr */
2022-11-23 15:44:27 -05:00
/* */
/* ************************************************************************** */
#include "pushswap.h"
2022-12-11 11:56:20 -05:00
long int ft_atoi(char *str)
2022-11-23 15:44:27 -05:00
{
2022-12-11 11:56:20 -05:00
long int nb;
int i;
int sign;
2022-11-23 15:44:27 -05:00
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);
}