Update Ex4 and Starting Ex5
This commit is contained in:
@@ -198,4 +198,4 @@ int main(void)
|
|||||||
free(result);
|
free(result);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}*/
|
}*/
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_split.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/03/18 10:29:59 by lclerel- #+# #+# */
|
||||||
|
/* Updated: 2026/03/18 18:19:30 by lclerel- ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|||||||
Reference in New Issue
Block a user