From a5c0814aa37e63b6efb0375ec62941791f6fd914 Mon Sep 17 00:00:00 2001 From: Anahit Sargsyan Date: Sun, 3 Dec 2023 18:03:56 +0400 Subject: [PATCH] added the ft_str_is_numeric() function --- ex00/ft_utils.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ex00/ft_utils.c b/ex00/ft_utils.c index c97ffe9..0db80a1 100644 --- a/ex00/ft_utils.c +++ b/ex00/ft_utils.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* utils.c :+: :+: :+: */ +/* ft_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: achubuko +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/02 21:56:30 by achubuko #+# #+# */ -/* Updated: 2023/12/02 23:45:23 by achubuko ### ########.fr */ +/* Updated: 2023/12/03 18:03:15 by asargsya ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_utils.h" @@ -25,3 +25,20 @@ size_t ft_strlen(char *s) l++; return (l); } +int ft_str_is_numeric(char *str) +{ + int i; + + i = 0; + if (str[i] == '\0') + return (0); + while (str[i] != '\0') + { + if (str[i] < '0' || str[i] > '9') + return (0); + i++; + } + if (str[0] == '-') + return (-1); + return (1); +}