diff --git a/Makefile b/Makefile index c98e858..b118731 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: adjoly +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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) diff --git a/ft_putendl_fd.c b/ft_putendl_fd.c new file mode 100644 index 0000000..00bfae5 --- /dev/null +++ b/ft_putendl_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/ft_split.c b/ft_split.c new file mode 100644 index 0000000..b2bae14 --- /dev/null +++ b/ft_split.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/ft_strjoin.c b/ft_strjoin.c index 87caffe..f296829 100644 --- a/ft_strjoin.c +++ b/ft_strjoin.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/ft_substr.c b/ft_substr.c index c6d5b1d..edcef0a 100644 --- a/ft_substr.c +++ b/ft_substr.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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++; diff --git a/libft.h b/libft.h index 1ccdd3a..4684357 100644 --- a/libft.h +++ b/libft.h @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 \ No newline at end of file