From 19964c7a382bcc5c0f09b1233b54b559c44e3a28 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 5 Feb 2020 01:29:21 +0100 Subject: fixing ft_split_strict --- Makefile | 4 ++-- ft_split_strict.c | 14 ++++++-------- libft.h | 4 +++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 814a2d6..1041c4b 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: cacharle +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/10/08 15:45:53 by cacharle #+# #+# # -# Updated: 2020/02/04 04:08:01 by cacharle ### ########.fr # +# Updated: 2020/02/04 20:22:40 by cacharle ### ########.fr # # # # **************************************************************************** # @@ -28,7 +28,7 @@ SRC = ft_atoi.c ft_bzero.c ft_isalnum.c ft_isalpha.c ft_isascii.c ft_isdigit.c f ft_strncat.c ft_strncmp.c ft_strncpy.c ft_strnequ.c ft_strnew.c ft_strnstr.c \ ft_strrchr.c ft_split.c ft_strstr.c ft_substr.c ft_strtrim.c ft_tolower.c \ ft_toupper.c ft_strlcpy.c ft_calloc.c ft_strcount.c ft_memswap.c ft_qsort.c \ - ft_abs.c ft_strtol.c ft_isspace.c + ft_abs.c ft_strtol.c ft_isspace.c ft_split_strict.c OBJ = $(SRC:.c=.o) INCLUDE = libft.h diff --git a/ft_split_strict.c b/ft_split_strict.c index 9964f4c..69d2220 100644 --- a/ft_split_strict.c +++ b/ft_split_strict.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/04 05:20:26 by cacharle #+# #+# */ -/* Updated: 2020/02/04 05:21:29 by cacharle ### ########.fr */ +/* Updated: 2020/02/04 23:27:46 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ static size_t count_segment(char const *s, char c) while (s[++i]) if (s[i] == c) counter++; - return (counter); + return (counter + 1); } static char *ft_strndup(const char *s1, size_t n) @@ -53,7 +53,7 @@ static void *destroy_strs(char **strs) return (NULL); } -char **ft_split(char const *s, char c) +char **ft_split_strict(char const *s, char c) { char **strs; size_t tab_counter; @@ -63,20 +63,18 @@ char **ft_split(char const *s, char c) if (s == NULL) return (NULL); tab_counter = count_segment(s, c); - if ((strs = (char**)malloc(sizeof(char*) * (tab_counter + 1))) == NULL) + if ((strs = (char**)malloc(sizeof(char*) * (tab_counter + 20))) == NULL) return (NULL); tab_counter = 0; j = -1; - while (s[++j]) + while (s[++j] != '\0') { - if (s[j] == c) - continue ; i = 0; while (s[j + i] && s[j + i] != c) i++; if ((strs[tab_counter++] = ft_strndup(&s[j], i)) == NULL) return (destroy_strs(strs)); - j += i - 1; + j += i; } strs[tab_counter] = NULL; return (strs); diff --git a/libft.h b/libft.h index 49996c3..99c71db 100644 --- a/libft.h +++ b/libft.h @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 09:45:02 by cacharle #+# #+# */ -/* Updated: 2020/02/04 04:41:08 by cacharle ### ########.fr */ +/* Updated: 2020/02/04 20:23:20 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ # include # include +# include # define TRUE 1 # define FALSE 0 @@ -82,6 +83,7 @@ char *ft_substr(char const *s, unsigned int start, size_t len); char *ft_strjoin(char const *s1, char const *s2); char *ft_strtrim(char const *s1, char const *set); char **ft_split(char const *s, char c); +char **ft_split_strict(char const *s, char c); char *ft_itoa(int n); void ft_putendl(char *s); void ft_putchar(char c); -- cgit