42_push_swap/ft_isnum.c

39 lines
1.3 KiB
C
Raw Normal View History

2022-11-23 15:44:27 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/08 18:43:06 by cchauvet #+# #+# */
2023-01-19 11:30:22 -05:00
/* Updated: 2023/01/19 17:28:17 by cchauvet ### ########.fr */
2022-11-23 15:44:27 -05:00
/* */
/* ************************************************************************** */
#include "pushswap.h"
int ft_isnum(char *str)
{
2022-12-11 11:56:20 -05:00
long int i;
int sign;
sign = 1;
if (*str == '-')
sign = -1;
i = 0;
if (*str == '-' || *str == '+')
str++;
if (*str == '\0')
return (0);
2022-11-23 15:44:27 -05:00
while (*str != '\0')
{
2023-01-19 11:30:22 -05:00
i = i * 10 + *str - '0';
2022-12-11 11:56:20 -05:00
if (i * sign > INT_MAX || INT_MIN > i * sign)
return (0);
if (!(*str >= '0' && *str <= '9'))
2022-11-23 15:44:27 -05:00
return (0);
str++;
}
return (1);
}