42-archive/libft/srcs/sstr/ft_sstradd.c
2017-03-31 21:42:02 +02:00

32 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sstradd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 18:03:58 by jhalford #+# #+# */
/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_sstradd(char **sstr, char *new)
{
int size;
char **newlist;
size = 0;
if (sstr)
while (sstr[size])
size++;
if (!(newlist = (char **)ft_memalloc(sizeof(char *) * (size + 2))))
return (NULL);
if (sstr)
ft_memcpy(newlist, sstr, sizeof(char*) * size);
newlist[size] = ft_strdup(new);
newlist[size + 1] = NULL;
free(sstr);
return (newlist);
}