1
0
cub3d/libft/str/ft_atoi.c
2024-09-10 16:27:06 +02:00

41 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 15:05:03 by madumerg #+# #+# */
/* Updated: 2024/03/26 16:17:58 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int i;
int r;
int s;
i = 0;
r = 0;
s = 1;
if (!str)
return (0);
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
s = -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
r = r * 10 + str[i] - '0';
i++;
}
return (r *= s);
}