Update Ex5
This commit is contained in:
@@ -6,35 +6,13 @@
|
||||
/* 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 */
|
||||
/* Updated: 2026/03/19 10:07:18 by syxpi ### ########.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;
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user