cub3d/libft/src/str/ft_atoi.c
2025-05-03 22:54:55 +02:00

37 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/15 17:02:23 by tchampio #+# #+# */
/* Updated: 2024/10/15 17:23:50 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/libft.h"
int ft_atoi(const char *s)
{
int isnegative;
int res;
res = 0;
isnegative = 1;
while (*s == ' ' || *s == '\f' || *s == '\r' || *s == '\v' || *s == '\t'
|| *s == '\n')
s++;
if (*s == '-' || *s == '+')
{
if (*s == '-')
isnegative = -1;
s++;
}
while (*s >= '0' && *s <= '9')
{
res = (res * 10) + (*s - '0');
s++;
}
return (res * isnegative);
}