42_minitalk/libftx/extra/ft_isnum.c

39 lines
1.3 KiB
C
Raw Permalink Normal View History

2023-01-23 07:22:30 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/08 18:43:06 by cchauvet #+# #+# */
/* Updated: 2023/01/20 17:14:08 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "extra.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')
{
i = i * 10 + *str - '0';
if (i * sign > INT_MAX || INT_MIN > i * sign)
return (0);
if (!(*str >= '0' && *str <= '9'))
return (0);
str++;
}
return (1);
}