From 840a26935181c35cd8416853f1aad9a0bf99621f Mon Sep 17 00:00:00 2001 From: narnaud Date: Sat, 21 May 2022 18:16:54 +0200 Subject: [PATCH] little adds --- Makefile | 21 +++++++++++++-------- conv/ft_itox.c | 0 conv/ft_utoa.c | 0 dlist/ft_add.c | 0 dlist/ft_n.c | 0 dlist/ft_to_arr.c | 4 ++-- i_slist/ft_first.c | 0 i_slist/ft_free.c | 0 i_slist/ft_is_in.c | 0 is/ft_islower.c | 0 is/ft_isnumber.c | 26 ++++++++++++++++++++++++++ is/ft_isspace.c | 4 ++-- is/ft_isupper.c | 0 libft.h | 7 ++++++- mem/ft_free_split.c | 0 nbr/ft_croissant.c | 0 nbr/ft_decroissant.c | 0 nbr/ft_max.c | 21 +++++++++++++++++++++ nbr/ft_min.c | 21 +++++++++++++++++++++ nbr/ft_nbrlen.c | 0 str/ft_join_with.c | 27 +++++++++++++++++++++++++++ str/ft_rev.c | 0 str/ft_split.c | 2 +- 23 files changed, 119 insertions(+), 14 deletions(-) mode change 100644 => 100755 conv/ft_itox.c mode change 100644 => 100755 conv/ft_utoa.c mode change 100644 => 100755 dlist/ft_add.c mode change 100644 => 100755 dlist/ft_n.c mode change 100644 => 100755 dlist/ft_to_arr.c mode change 100644 => 100755 i_slist/ft_first.c mode change 100644 => 100755 i_slist/ft_free.c mode change 100644 => 100755 i_slist/ft_is_in.c mode change 100644 => 100755 is/ft_islower.c create mode 100644 is/ft_isnumber.c mode change 100644 => 100755 is/ft_isspace.c mode change 100644 => 100755 is/ft_isupper.c mode change 100644 => 100755 mem/ft_free_split.c mode change 100644 => 100755 nbr/ft_croissant.c mode change 100644 => 100755 nbr/ft_decroissant.c create mode 100755 nbr/ft_max.c create mode 100755 nbr/ft_min.c mode change 100644 => 100755 nbr/ft_nbrlen.c create mode 100644 str/ft_join_with.c mode change 100644 => 100755 str/ft_rev.c diff --git a/Makefile b/Makefile index 08b2fe0..e3f3af6 100755 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ NAME = libft.a SRCS = is/ft_isalpha.c is/ft_isdigit.c is/ft_isascii.c is/ft_isprint.c \ - is/ft_isalnum.c + is/ft_isalnum.c is/ft_isspace.c is/ft_isnumber.c SRCS += str/ft_len.c str/ft_lcpy.c str/ft_lcat.c str/ft_chr.c \ str/ft_rchr.c str/ft_ncmp.c str/ft_nstr.c str/ft_dup.c \ str/ft_sub.c str/ft_join.c str/ft_trim.c str/ft_split.c \ - str/ft_rev.c str/ft_mapi.c str/ft_iteri.c + str/ft_rev.c str/ft_mapi.c str/ft_iteri.c str/ft_join_with.c SRCS += conv/ft_toupper.c conv/ft_tolower.c conv/ft_atoi.c conv/ft_itoa.c \ conv/ft_itox.c conv/ft_utoa.c @@ -17,7 +17,8 @@ SRCS += mem/ft_bzero.c mem/ft_memset.c mem/ft_memchr.c mem/ft_memcpy.c \ SRCS += put/ft_putchar_fd.c put/ft_putnbr_fd.c put/ft_putendl_fd.c \ put/ft_putstr_fd.c -SRCS += nbr/ft_nbrlen.c nbr/ft_croissant.c nbr/ft_decroissant.c +SRCS += nbr/ft_nbrlen.c nbr/ft_croissant.c nbr/ft_decroissant.c nbr/ft_max.c \ + nbr/ft_min.c SRCS += slist/ft_size.c slist/ft_new.c slist/ft_last.c \ slist/ft_add_back.c slist/ft_add_front.c slist/ft_delone.c \ @@ -36,19 +37,23 @@ RM = rm -rf CFLAGS = -Wall -Wextra -Werror .c.o: - ${CC} ${CFLAGS} -c $< -o ${<:.c=.o} + @${CC} ${CFLAGS} -c $< -o ${<:.c=.o} all : $(NAME) $(NAME): $(OBJS) - ${AR} ${NAME} ${OBJS} + @echo "Making libft." + @${AR} ${NAME} ${OBJS} + @echo "Done." clean: - ${RM} ${OBJS} - ${RM} ${OBJS_BONUS} + @echo "Cleaning libft." + @${RM} ${OBJS} + @${RM} ${OBJS_BONUS} + @echo "Done." fclean: clean - ${RM} ${NAME} + @${RM} ${NAME} re: fclean all diff --git a/conv/ft_itox.c b/conv/ft_itox.c old mode 100644 new mode 100755 diff --git a/conv/ft_utoa.c b/conv/ft_utoa.c old mode 100644 new mode 100755 diff --git a/dlist/ft_add.c b/dlist/ft_add.c old mode 100644 new mode 100755 diff --git a/dlist/ft_n.c b/dlist/ft_n.c old mode 100644 new mode 100755 diff --git a/dlist/ft_to_arr.c b/dlist/ft_to_arr.c old mode 100644 new mode 100755 index 8eb7752..5b8a16a --- a/dlist/ft_to_arr.c +++ b/dlist/ft_to_arr.c @@ -33,9 +33,9 @@ char **ft_dlst_to_arr(t_dlist *ptr) while (count--) { ret[count] = last->content; - tmp = last; + tmp = last->previous; free(last); - last = tmp->previous; + last = tmp; } return (ret); } diff --git a/i_slist/ft_first.c b/i_slist/ft_first.c old mode 100644 new mode 100755 diff --git a/i_slist/ft_free.c b/i_slist/ft_free.c old mode 100644 new mode 100755 diff --git a/i_slist/ft_is_in.c b/i_slist/ft_is_in.c old mode 100644 new mode 100755 diff --git a/is/ft_islower.c b/is/ft_islower.c old mode 100644 new mode 100755 diff --git a/is/ft_isnumber.c b/is/ft_isnumber.c new file mode 100644 index 0000000..6053f7a --- /dev/null +++ b/is/ft_isnumber.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isnumber.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud@student.42nice.fr +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/05/18 16:18:15 by narnaud@stude #+# #+# */ +/* Updated: 2022/05/18 16:21:52 by narnaud@stude ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +int ft_isnumber(char *str) +{ + if (*str == '-' || *str == '+') + str++; + while (*str) + { + if (!ft_isdigit(*str)) + return (0); + str++; + } + return (1); +} diff --git a/is/ft_isspace.c b/is/ft_isspace.c old mode 100644 new mode 100755 index 9cbbcba..139f0a3 --- a/is/ft_isspace.c +++ b/is/ft_isspace.c @@ -6,13 +6,13 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/03/24 10:05:51 by narnaud #+# #+# */ -/* Updated: 2022/03/24 10:06:15 by narnaud ### ########.fr */ +/* Updated: 2022/05/03 09:47:28 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" -int ft_isspace(char c) +int ft_isspace(int c) { if (c > 8 && c < 14) return (1); diff --git a/is/ft_isupper.c b/is/ft_isupper.c old mode 100644 new mode 100755 diff --git a/libft.h b/libft.h index 91a6acc..de7b0c1 100755 --- a/libft.h +++ b/libft.h @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/19 14:42:45 by narnaud #+# #+# */ -/* Updated: 2022/03/25 13:31:43 by narnaud ### ########.fr */ +/* Updated: 2022/05/18 16:25:27 by narnaud@stude ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,6 +44,8 @@ int ft_isascii(int ch); int ft_isdigit(int ch); int ft_isprint(int ch); int ft_isalnum(int ch); +int ft_isspace(int ch); +int ft_isnumber(char *str); void *ft_memchr(const void *b, int c, size_t n); int ft_memcmp(const void *s1, const void *s2, size_t n); void *ft_memcpy(void *dst, const void *src, size_t n); @@ -55,6 +57,8 @@ size_t ft_ulen(unsigned int nbr); size_t ft_longbaselen(long nbr, size_t base); int ft_croissant(int a, int b); int ft_decroissant(int a, int b); +int ft_max(int a, int b); +int ft_min(int a, int b); void *ft_memset(void *b, int c, size_t len); char *ft_strchr(const char *s, int c); @@ -71,6 +75,7 @@ int ft_tolower(int c); int ft_toupper(int c); char *ft_substr(char const *s, unsigned int start, size_t len); char *ft_strjoin(const char *s1, const char *s2); +char *ft_strjoin_with(char *s1, char *s2, char *inter); char *ft_strtrim(char const *s1, char const *set); char **ft_split(char const *str, char ch); char *ft_itoa(int n); diff --git a/mem/ft_free_split.c b/mem/ft_free_split.c old mode 100644 new mode 100755 diff --git a/nbr/ft_croissant.c b/nbr/ft_croissant.c old mode 100644 new mode 100755 diff --git a/nbr/ft_decroissant.c b/nbr/ft_decroissant.c old mode 100644 new mode 100755 diff --git a/nbr/ft_max.c b/nbr/ft_max.c new file mode 100755 index 0000000..53a7605 --- /dev/null +++ b/nbr/ft_max.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_max.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud@student.42nice.fr +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/05/07 22:56:56 by narnaud@stude #+# #+# */ +/* Updated: 2022/05/07 22:57:21 by narnaud@stude ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +int ft_max(int a, int b) +{ + if (a > b) + return (a); + else + return (b); +} diff --git a/nbr/ft_min.c b/nbr/ft_min.c new file mode 100755 index 0000000..45a9ab6 --- /dev/null +++ b/nbr/ft_min.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_min.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud@student.42nice.fr +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/05/07 22:56:56 by narnaud@stude #+# #+# */ +/* Updated: 2022/05/09 08:58:50 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +int ft_min(int a, int b) +{ + if (a < b) + return (a); + else + return (b); +} diff --git a/nbr/ft_nbrlen.c b/nbr/ft_nbrlen.c old mode 100644 new mode 100755 diff --git a/str/ft_join_with.c b/str/ft_join_with.c new file mode 100644 index 0000000..66860a5 --- /dev/null +++ b/str/ft_join_with.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_join_with.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/05/17 09:44:59 by narnaud #+# #+# */ +/* Updated: 2022/05/17 09:56:37 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +char *ft_strjoin_with(char *s1, char *s2, char *inter) +{ + int path_length; + char *ret; + + path_length = ft_strlen(s1) + ft_strlen(s2) + ft_strlen(inter) + 1; + ret = ft_calloc(path_length, sizeof(char)); + ft_memcpy(ret, s1, ft_strlen(s1)); + ft_memcpy(ret + ft_strlen(s1), inter, ft_strlen(inter)); + ft_memcpy(ret + ft_strlen(s1) + ft_strlen(inter), \ + s2, ft_strlen(s2)); + return (ret); +} diff --git a/str/ft_rev.c b/str/ft_rev.c old mode 100644 new mode 100755 diff --git a/str/ft_split.c b/str/ft_split.c index 026999f..a2e0411 100755 --- a/str/ft_split.c +++ b/str/ft_split.c @@ -38,5 +38,5 @@ char **ft_split(const char *str, char c) word[j++] = str[i]; } words = ft_dlst_add(words, word); - return ((char **)ft_dlst_to_arr(words)); + return (ft_dlst_to_arr(words)); }