fix: count the nb of ','

This commit is contained in:
Camille Chauvet 2023-06-16 16:33:53 +00:00
parent 217a220705
commit 101018f0c1
4 changed files with 38 additions and 9 deletions

View File

@ -6,13 +6,13 @@
# By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ # # By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/09/27 08:39:27 by cchauvet #+# #+# # # Created: 2022/09/27 08:39:27 by cchauvet #+# #+# #
# Updated: 2023/05/03 11:01:55 by cchauvet ### ########.fr # # Updated: 2023/06/16 16:32:17 by cchauvet ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
CC = clang CC = clang
SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c ft_swap.c ft_tablen.c ft_atoul.c ft_atoul_check.c SRCS = ft_contain_only.c ft_freer.c ft_is_in.c ft_random_generator.c ft_strchri.c ft_strcmp.c ft_strfjoin.c ft_strgen.c ft_strmerger.c ft_strndup.c ft_tabrealloc.c ft_ultoa_base.c ft_swap.c ft_tablen.c ft_atoul.c ft_atoul_check.c ft_count.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 14:03:10 by cchauvet #+# #+# */ /* Created: 2023/01/04 14:03:10 by cchauvet #+# #+# */
/* Updated: 2023/06/12 14:17:50 by cchauvet ### ########.fr */ /* Updated: 2023/06/16 16:31:33 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,6 +19,7 @@
# include <fcntl.h> # include <fcntl.h>
# include "../libft/libft.h" # include "../libft/libft.h"
size_t ft_count(const char *str, char c);
unsigned long ft_atoul(const char str[]); unsigned long ft_atoul(const char str[]);
int ft_atoul_check(const char str[]); int ft_atoul_check(const char str[]);
size_t ft_tablen(const void **tab); size_t ft_tablen(const void **tab);

29
libftx/extra/ft_count.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_count.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/16 18:27:16 by cchauvet #+# #+# */
/* Updated: 2023/06/16 16:29:22 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./extra.h"
size_t ft_count(const char *str, char c)
{
size_t i;
size_t out;
i = 0;
out = 0;
while (str[i] != '\0')
{
if (str[i] == c)
out++;
i++;
}
return (out);
}

View File

@ -6,7 +6,7 @@
/* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */ /* By: cchauvet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/16 17:28:58 by cchauvet #+# #+# */ /* Created: 2023/05/16 17:28:58 by cchauvet #+# #+# */
/* Updated: 2023/05/16 19:02:08 by cchauvet ### ########.fr */ /* Updated: 2023/06/16 16:31:06 by cchauvet ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -65,15 +65,14 @@ int set_color(long long *color, const char *key, const char *value)
ft_eprintf("map: %s redefinition", key); ft_eprintf("map: %s redefinition", key);
return (1); return (1);
} }
tab = ft_split(value, ','); if (ft_count(value, ',') != 2)
if (tab == NULL)
return (1);
if (ft_tablen((const void **) tab) != 3)
{ {
ft_freer_tab_ultimate(1, tab);
ft_eprintf("map: invalid format %s %s", key, value); ft_eprintf("map: invalid format %s %s", key, value);
return (1); return (1);
} }
tab = ft_split(value, ',');
if (tab == NULL)
return (1);
*color = get_color((const char **) tab); *color = get_color((const char **) tab);
ft_freer_tab_ultimate(1, tab); ft_freer_tab_ultimate(1, tab);
return (*color == -1); return (*color == -1);