NIQUE TA GROSSE MÈRE LA SALOPE PUTE PUTE -Camille Chauvet 2004/2023
This commit is contained in:
50
utils/ft_atoi_check.c
Normal file
50
utils/ft_atoi_check.c
Normal file
@ -0,0 +1,50 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi_check.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */
|
||||
/* Updated: 2022/12/08 16:37:19 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
static int ft_isspace(char c)
|
||||
{
|
||||
if (c == ' ' || c == '\f'
|
||||
||c == '\n' || c == '\r' || c == '\t' || c == '\v')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_atoi_check(const char *nptr)
|
||||
{
|
||||
long result;
|
||||
int sign;
|
||||
|
||||
while (ft_isspace(*nptr))
|
||||
nptr++;
|
||||
sign = 1;
|
||||
if (*nptr == '+' || *nptr == '-')
|
||||
{
|
||||
if (*nptr == '-')
|
||||
sign = -1;
|
||||
nptr++;
|
||||
}
|
||||
result = 0;
|
||||
while (*nptr >= '0' && *nptr <= '9')
|
||||
{
|
||||
result = result * 10 + *nptr++ - '0';
|
||||
if ((result > 2147483647 && sign == 1)
|
||||
|| (result > 2147483648 && sign == -1))
|
||||
return (0);
|
||||
}
|
||||
if (*nptr--)
|
||||
return (0);
|
||||
if (*nptr == '-' || *nptr == '+')
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
@ -25,5 +25,6 @@ int ft_str_is_empty(const char *str);
|
||||
char **ft_split_quoted(const char *s, char c);
|
||||
void ft_strshift(char *str, int shift);
|
||||
char *ft_quote_remover(char *str);
|
||||
int ft_atoi_check(const char *nptr);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user