From edc4b6cfd8215285d0be4feb21db7adec8385e39 Mon Sep 17 00:00:00 2001 From: lclerel- lclerel- Date: Wed, 18 Mar 2026 19:46:40 +0100 Subject: [PATCH] Update Ex4 and Starting Ex5 --- ex4/ft_convert_base.c | 2 +- ex5/ft_split.c | 74 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/ex4/ft_convert_base.c b/ex4/ft_convert_base.c index f1990ac..a9cb7dc 100644 --- a/ex4/ft_convert_base.c +++ b/ex4/ft_convert_base.c @@ -198,4 +198,4 @@ int main(void) free(result); } return (0); -}*/ +}*/ \ No newline at end of file diff --git a/ex5/ft_split.c b/ex5/ft_split.c index e69de29..778c6cd 100644 --- a/ex5/ft_split.c +++ b/ex5/ft_split.c @@ -0,0 +1,74 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lclerel- +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/03/18 10:29:59 by lclerel- #+# #+# */ +/* Updated: 2026/03/18 18:19:30 by lclerel- ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +char **ft_split(char *str, char *charset) +{ + int i; + int j; + int k; + char **res; + + res = malloc(sizeof(char *) * (ft_words(str, charset) + 1)); + if (!res || (i = 0) == 1) + return (NULL); + j = 0; + while (str[i]) + { + while (str[i] && ft_sep(str[i], charset)) + i++; + res[j] = malloc(sizeof(char) * (len + 1)); + if (!res[j]) + return (NULL); + if (str[i] ) + } +} + +int ft_sep(char c, char *charset) +{ + int i; + + i = 0; + while (charset[i]) + { + if (c == charset[i]) + return (1); + i++; + } + return (0); +} + +int ft_words(char *str, char *charset) +{ + int i; + int count; + + count = 0; + i = 0; + while (str[i]) + { + if (ft_sep(str[i], charset) == 0 + && (i == 0 || is_sep(str[i - 1], charset) == 1)) + { + count++; + } + i++; + } + return (count); +} + +/*int main(void) +{ + +}*/