1
0
libft_new/ft_split.c

59 lines
1.5 KiB
C
Raw Normal View History

2023-11-10 18:49:34 +01:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 19:04:42 by adjoly #+# #+# */
2023-11-11 01:28:12 +01:00
/* Updated: 2023/11/11 00:36:54 by adjoly ### ########.fr */
2023-11-10 18:49:34 +01:00
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_countword(char const *s, char sep)
{
int i;
int w_count;
i = 0;
2023-11-11 01:28:12 +01:00
w_count = 0;
2023-11-10 18:49:34 +01:00
while (s[i])
{
2023-11-11 01:28:12 +01:00
if (s[i] != sep && (i == 0 || s[i - 1] == sep))
2023-11-10 18:49:34 +01:00
w_count++;
i++;
}
return (w_count);
}
2023-11-11 01:28:12 +01:00
const int ft_countletter(char const *s, char sep)
{
int i;
i = 0;
while (s[i] != sep || s[i] != '\0')
i++;
return (i);
}
2023-11-10 18:49:34 +01:00
char **ft_split(char const *s, char c)
{
int w_count;
char **result;
w_count = ft_countword(s, c);
2023-11-11 01:28:12 +01:00
result = malloc((w_count + 1) * sizeof(char *));
if (result == NULL)
return (NULL);
while (s[i])
{
while ()
{
}
}
2023-11-10 18:49:34 +01:00
return (result);
}