Browse Source

strnew and strappend

master
nicolas-arnaud 2 years ago
parent
commit
91542393af
  1. 3
      Makefile
  2. 10
      libft.h
  3. 8
      slist/ft_add_back.c
  4. 8
      slist/ft_add_front.c
  5. 16
      str/ft_append.c
  6. 18
      str/ft_new.c

3
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

10
libft.h

@ -10,8 +10,7 @@
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
#pragma once
# include <stddef.h>
# include <stdlib.h>
@ -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

8
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;
}

8
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;
}

16
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);
}

18
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);
}
Loading…
Cancel
Save