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: 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);
|
||
|
}
|