42_Philosopher/philo/utils/ft_isnum.c
Camille Chauvet aefb6ceec0 bozosujet
2023-05-17 13:28:42 +02:00

35 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/08 14:43:33 by cchauvet #+# #+# */
/* Updated: 2023/04/19 13:49:58 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "../philo.h"
#include <stddef.h>
#include <limits.h>
bool ft_isnum(char str[])
{
size_t i;
size_t num;
num = 0;
i = 0;
while (str[i] != '\0')
{
if (str[i] > '9' || str[i] < '0')
return (0);
num = num * 10 + str[i] - 48;
if (num > INT_MAX)
return (0);
i++;
}
return (1);
}