ajout ft_atoi_check
This commit is contained in:
parent
ecad503098
commit
a020fd795c
2
Makefile
2
Makefile
|
@ -16,7 +16,7 @@ ft_strlcat.c ft_toupper.c ft_tolower.c ft_strchr.c ft_strrchr.c ft_strncmp.c \
|
||||||
ft_memchr.c ft_memcmp.c ft_strnstr.c ft_atoi.c ft_calloc.c ft_strdup.c \
|
ft_memchr.c ft_memcmp.c ft_strnstr.c ft_atoi.c ft_calloc.c ft_strdup.c \
|
||||||
ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c \
|
ft_substr.c ft_strjoin.c ft_strtrim.c ft_split.c ft_itoa.c ft_strmapi.c \
|
||||||
ft_striteri.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c \
|
ft_striteri.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c \
|
||||||
ft_get_size.c ft_power.c
|
ft_get_size.c ft_power.c ft_atoi_check.c
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
BONUS_SRCS = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c \
|
BONUS_SRCS = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c \
|
||||||
ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c
|
ft_lstadd_back.c ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c
|
||||||
|
|
50
ft_atoi_check.c
Normal file
50
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 "libft.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);
|
||||||
|
}
|
1
libft.h
1
libft.h
|
@ -66,5 +66,6 @@ void ft_lstdelone(t_list *lst, void (*del)(void*));
|
||||||
void ft_lstclear(t_list **lst, void (*del)(void*));
|
void ft_lstclear(t_list **lst, void (*del)(void*));
|
||||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||||
|
int ft_atoi_check(const char *nptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue