diff --git a/Makefile b/Makefile index e3f3af6..dbfa767 100755 --- a/Makefile +++ b/Makefile @@ -6,7 +6,8 @@ SRCS = is/ft_isalpha.c is/ft_isdigit.c is/ft_isascii.c is/ft_isprint.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_join_with.c + str/ft_rev.c str/ft_mapi.c str/ft_iteri.c str/ft_join_with.c \ + str/ft_new.c str/ft_append.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 diff --git a/libft.h b/libft.h index de7b0c1..20b31d4 100755 --- a/libft.h +++ b/libft.h @@ -10,8 +10,7 @@ /* */ /* ************************************************************************** */ -#ifndef LIBFT_H -# define LIBFT_H +#pragma once # include # include @@ -87,12 +86,14 @@ void ft_putchar_fd(char c, int fd); void ft_putstr_fd(char *s, int fd); void ft_putendl_fd(char *s, int fd); void ft_putnbr_fd(int n, int fd); +char *ft_append(char *s1, char *s2); +char *ft_strnew(int n, char c); t_slist *ft_slst_new(void *content); -void ft_slst_add_front(t_slist **alst, t_slist *new); +void ft_slst_add_front(t_slist **alst, t_slist *new_e); int ft_slst_size(t_slist *lst); t_slist *ft_slst_last(t_slist *lst); -void ft_slst_add_back(t_slist **alst, t_slist *new); +void ft_slst_add_back(t_slist **alst, t_slist *new_e); void ft_slst_delone(t_slist *lst, void (*del)(void *)); void ft_slst_clear(t_slist **lst, void (*del)(void *)); void ft_slst_iter(t_slist *lst, void (*f)(void *)); @@ -105,4 +106,3 @@ int ft_ilst_is_in(int value, t_i_slist lst); t_dlist *ft_dlst_add(t_dlist *prev, void *content); t_dlist *ft_dlst_n(t_dlist *lst, size_t n); char **ft_dlst_to_arr(t_dlist *ptr); -#endif diff --git a/slist/ft_add_back.c b/slist/ft_add_back.c index 5311366..6d53548 100755 --- a/slist/ft_add_back.c +++ b/slist/ft_add_back.c @@ -12,17 +12,17 @@ #include "../libft.h" -void ft_slst_add_back(t_slist **alst, t_slist *new) +void ft_slst_add_back(t_slist **alst, t_slist *new_e) { t_slist *i_cell; - if (!alst || !new) + if (!alst || !new_e) return ; if (*alst) { i_cell = ft_slst_last(*alst); - i_cell->next = new; + i_cell->next = new_e; } else - *alst = new; + *alst = new_e; } diff --git a/slist/ft_add_front.c b/slist/ft_add_front.c index 32fcb60..26229c2 100755 --- a/slist/ft_add_front.c +++ b/slist/ft_add_front.c @@ -12,11 +12,11 @@ #include "../libft.h" -void ft_slst_add_front(t_slist **alst, t_slist *new) +void ft_slst_add_front(t_slist **alst, t_slist *new_e) { - if (!alst || !new) + if (!alst || !new_e) return ; if (*alst) - new->next = *alst; - *alst = new; + new_e->next = *alst; + *alst = new_e; } diff --git a/str/ft_append.c b/str/ft_append.c new file mode 100644 index 0000000..ff3362a --- /dev/null +++ b/str/ft_append.c @@ -0,0 +1,16 @@ +#include "../libft.h" + +char *ft_append(char *s1, char *s2) +{ + char *ret; + + ret = NULL; + if (!s1) + return (s2); + if (!s2) + return (s1); + ret = ft_strjoin(s1, s2); + free(s1); + free(s2); + return (ret); +} diff --git a/str/ft_new.c b/str/ft_new.c new file mode 100644 index 0000000..06d3f9e --- /dev/null +++ b/str/ft_new.c @@ -0,0 +1,18 @@ +#include "../libft.h" + +char *ft_strnew(int n, char c) +{ + char *str; + + str = NULL; + if (n < 0) + return (NULL); + str = malloc(n + 1); + if (!str) + return (NULL); + str[n] = '\0'; + while (--n >= 0) + str[n] = c; + return (str); +} +