From 80d8285fe5d6d03247d3ce21fce2358da6e5009f Mon Sep 17 00:00:00 2001 From: Timo Schmidt Date: Fri, 31 Mar 2023 22:06:11 +0200 Subject: [PATCH] Whitespace disallowed --- ex04/ft_putnbr_base.c | 14 ++++++++++++-- ex05/ft_atoi_base.c | 18 +++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/ex04/ft_putnbr_base.c b/ex04/ft_putnbr_base.c index 354007e..7821ff0 100644 --- a/ex04/ft_putnbr_base.c +++ b/ex04/ft_putnbr_base.c @@ -6,13 +6,23 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/30 22:50:52 by tosuman #+# #+# */ -/* Updated: 2023/03/30 22:50:53 by tosuman ### ########.fr */ +/* Updated: 2023/03/31 22:05:08 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ #include #include +int ft_isspace(char c) +{ + return (c == ' ' + || c == '\t' + || c == '\n' + || c == '\r' + || c == '\f' + || c == '\v'); +} + unsigned int char_count(const char *str, char c) { unsigned int count; @@ -35,7 +45,7 @@ unsigned int is_valid_base(const char *base) size = 0; while (*base) { - if (*base == '+' || *base == '-') + if (*base == '+' || *base == '-' || ft_isspace(*base)) return (0); if (char_count(base, *base) > 1) return (0); diff --git a/ex05/ft_atoi_base.c b/ex05/ft_atoi_base.c index d92fac1..ca60f46 100644 --- a/ex05/ft_atoi_base.c +++ b/ex05/ft_atoi_base.c @@ -6,10 +6,20 @@ /* By: tosuman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/03/30 22:47:43 by tosuman #+# #+# */ -/* Updated: 2023/03/30 22:47:43 by tosuman ### ########.fr */ +/* Updated: 2023/03/31 22:05:31 by tischmid ### ########.fr */ /* */ /* ************************************************************************** */ +int ft_isspace(char c) +{ + return (c == ' ' + || c == '\t' + || c == '\n' + || c == '\r' + || c == '\f' + || c == '\v'); +} + unsigned int char_count(const char *str, char c) { unsigned int count; @@ -32,7 +42,7 @@ unsigned int is_valid_base(const char *base) size = 0; while (*base) { - if (*base == '+' || *base == '-' || *base == ' ') + if (*base == '+' || *base == '-' || ft_isspace(*base)) return (0); if (char_count(base, *base) > 1) return (0); @@ -70,9 +80,7 @@ int ft_atoi_base(char *str, char *base) base_len = is_valid_base(base); if (!base_len) return (0); - while (*str == ' ' || *str == '\t' - || *str == '\n' || *str == '\r' - || *str == '\f' || *str == '\v') + while (ft_isspace(*str)) ++str; while (*str == '+' || *str == '-') if (*str++ == '-')