1
0

start ft_split

This commit is contained in:
2023-11-10 18:49:34 +01:00
parent dc75952973
commit 63184fceea
6 changed files with 68 additions and 7 deletions

View File

@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
# Updated: 2023/11/08 17:07:14 by adjoly ### ########.fr #
# Updated: 2023/11/09 19:22:28 by adjoly ### ########.fr #
# #
# **************************************************************************** #
@ -43,6 +43,7 @@ SRCS = ft_atoi.c \
ft_strchr.c \
ft_strrchr.c \
ft_strnstr.c \
ft_putendl_fd.c \
OBJS = $(SRCS:.c=.o)

19
ft_putendl_fd.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 19:12:00 by adjoly #+# #+# */
/* Updated: 2023/11/09 19:15:50 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
}

40
ft_split.c Normal file
View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 19:04:42 by adjoly #+# #+# */
/* Updated: 2023/11/10 17:05:46 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_countword(char const *s, char sep)
{
int i;
int w_count;
i = 0;
if (s[i] != sep)
w_count++;
while (s[i])
{
if (s[i] == sep && s[i - 1] != sep)
w_count++;
i++;
}
return (w_count);
}
char **ft_split(char const *s, char c)
{
int w_count;
char **result;
w_count = ft_countword(s, c);
result = malloc(w_count);
return (result);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 13:44:09 by adjoly #+# #+# */
/* Updated: 2023/11/04 14:06:43 by adjoly ### ########.fr */
/* Updated: 2023/11/09 19:19:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,12 +14,12 @@
char *ft_strjoin(char const *s1, char const *s2)
{
int i;
// int i;
char *result;
size_t len_s1;
size_t len_s2;
i = 0;
// i = 0;
len_s1 = ft_strlen(s1);
len_s2 = ft_strlen(s2);
result = malloc(len_s1 + len_s2 + 1);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/02 17:59:58 by adjoly #+# #+# */
/* Updated: 2023/11/09 15:02:46 by adjoly ### ########.fr */
/* Updated: 2023/11/10 17:13:29 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,7 +28,7 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
result = malloc(((ft_strlen(s) - len) + 1) * sizeof(char));
if (result == NULL)
return (NULL);
while (i < len && s[start + i])
while (i < len - 1 && s[start + i])
{
result[i] = s[start + i];
i++;

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 10:06:03 by adjoly #+# #+# */
/* Updated: 2023/11/08 17:08:26 by adjoly ### ########.fr */
/* Updated: 2023/11/09 19:22:26 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -48,5 +48,6 @@ void *ft_memchr(const void *s, int c, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
char *ft_strrchr(const char *s, int c);
char *ft_strnstr(const char *big, const char *little, size_t len);
void ft_putendl_fd(char *s, int fd);
#endif