42_cube3D/libftx/extra/ft_atoul.c

39 lines
1.2 KiB
C
Raw Normal View History

2023-05-03 07:11:04 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoul.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/27 16:14:34 by cchauvet #+# #+# */
/* Updated: 2023/05/03 11:03:04 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "extra.h"
unsigned long ft_atoul(const char *str)
{
unsigned long out;
char sign;
size_t i;
sign = 1;
i = 0;
while (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
sign = -1;
if (str[i] == '+')
sign = 1;
i++;
}
out = 0;
while (str[i] >= '0' && str[i] <= '9')
{
out = out * 10 + str[i] - 48;
i++;
}
return (out * sign);
}