diff --git a/ex5/ft_split.c b/ex5/ft_split.c index 778c6cd..d1ad061 100644 --- a/ex5/ft_split.c +++ b/ex5/ft_split.c @@ -6,35 +6,13 @@ /* By: lclerel- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/03/18 10:29:59 by lclerel- #+# #+# */ -/* Updated: 2026/03/18 18:19:30 by lclerel- ### ########.fr */ +/* Updated: 2026/03/19 10:07:18 by syxpi ### ########.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; @@ -59,7 +37,7 @@ int ft_words(char *str, char *charset) while (str[i]) { if (ft_sep(str[i], charset) == 0 - && (i == 0 || is_sep(str[i - 1], charset) == 1)) + && (i == 0 || ft_sep(str[i - 1], charset) == 1)) { count++; } @@ -68,7 +46,47 @@ int ft_words(char *str, char *charset) return (count); } -/*int main(void) +void ft_putstr(char *str) { + int i; -}*/ + i = 0; + while (str[i]) + { + write(1, &str[i], 1); + i++; + } +} + +char **ft_split(char *str, char *charset) +{ + int i; + int j; + int len; + char **res; + + len = 0; + i = 0; + res = malloc(sizeof(char *) * (ft_words(str, charset) + 1)); + if (!res) + 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]); + } + return (res); +} + +int main(void) +{ + char *res; + + ft_split("Test=Test=Test=Test", "="); + ft_putstr(&res); +} diff --git a/ex5/test b/ex5/test new file mode 100755 index 0000000..d85118a Binary files /dev/null and b/ex5/test differ