39 lines
1.3 KiB
C
39 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_isnum.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/11/08 18:43:06 by cchauvet #+# #+# */
|
|
/* Updated: 2022/12/11 17:49:49 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "pushswap.h"
|
|
|
|
int ft_isnum(char *str)
|
|
{
|
|
long int i;
|
|
int sign;
|
|
|
|
sign = 1;
|
|
if (*str == '-')
|
|
sign = -1;
|
|
i = 0;
|
|
if (*str == '-' || *str == '+')
|
|
str++;
|
|
if (*str == '\0')
|
|
return (0);
|
|
while (*str != '\0')
|
|
{
|
|
if (i * sign > INT_MAX || INT_MIN > i * sign)
|
|
return (0);
|
|
if (!(*str >= '0' && *str <= '9'))
|
|
return (0);
|
|
i = i * 10 + *str - '0';
|
|
str++;
|
|
}
|
|
return (1);
|
|
}
|