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