ajout de ft_concat_free
This commit is contained in:
3
Makefile
3
Makefile
@@ -94,7 +94,8 @@ SRCS = ft_memset.c \
|
||||
ft_arraymap.c \
|
||||
ft_strmultisplit.c \
|
||||
\
|
||||
get_next_line.c
|
||||
get_next_line.c \
|
||||
ft_concat_free.c
|
||||
|
||||
ODIR = ./builds
|
||||
OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/25 14:45:53 by hulamy #+# #+# */
|
||||
/* Updated: 2020/02/25 18:43:18 by hulamy ### ########.fr */
|
||||
/* Updated: 2020/02/27 18:06:10 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -104,5 +104,6 @@ int *ft_arraymap(int *tab, int length, int(*f)(int));
|
||||
void ft_putnbrendl(int n);
|
||||
void ft_putnbrendl_fd(int n, int fd);
|
||||
int get_next_line(const int fd, char **line);
|
||||
char *ft_concat_free(char *str1, char *str2);
|
||||
|
||||
#endif
|
||||
|
||||
53
srcs/ft_concat_free.c
Normal file
53
srcs/ft_concat_free.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_concat_free.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/02/27 18:04:09 by hulamy #+# #+# */
|
||||
/* Updated: 2020/02/27 18:06:44 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** create a new string size of str1 + str2
|
||||
** fill it with concated str1 and str2m as "str1str2"
|
||||
** free the received strings str1 and str2
|
||||
** return the new string
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <stdio.h>
|
||||
** #include "libft.h"
|
||||
**
|
||||
** char *ft_concat_free(char *str1, char *str2);
|
||||
**
|
||||
** int main(int ac, char **av)
|
||||
** {
|
||||
** if (ac != 3)
|
||||
** return (0);
|
||||
** printf("%s\n", ft_concat_free(ft_strdup(av[1]), ft_strdup(av[2])));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_concat_free(char *str1, char *str2)
|
||||
{
|
||||
char *cat;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
cat = ft_memalloc(sizeof(char) * (ft_strlen(str1) + ft_strlen(str2) + 1));
|
||||
i = -1;
|
||||
j = 0;
|
||||
while (str1[++i])
|
||||
cat[i] = str1[i];
|
||||
while (str2[j])
|
||||
cat[i++] = str2[j++];
|
||||
free(str1);
|
||||
free(str2);
|
||||
return (cat);
|
||||
}
|
||||
Reference in New Issue
Block a user