42_cube3D/libftx/extra/ft_atoul_check.c

33 lines
1.2 KiB
C
Raw Normal View History

2023-05-03 07:11:04 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoul_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/08 14:43:33 by cchauvet #+# #+# */
/* Updated: 2023/05/02 13:15:12 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./extra.h"
int ft_atoul_check(const char str[])
{
size_t i;
unsigned long num;
num = 0;
i = 0;
while (str[i] != '\0')
{
if (str[i] > '9' || str[i] < '0')
return (0);
if (num > num * 10 + str[i] - '0')
return (0);
num = num * 10 + str[i] - 48;
i++;
}
return (1);
}