ft_tabjoin.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_tabjoin.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@student.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2017/02/23 01:28:42 by bchanot #+# #+# */
  9. /* Updated: 2018/10/29 11:52:02 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "libft.h"
  13. char **ft_tabjoin(char **tabl, const char *const src)
  14. {
  15. char **tmp;
  16. size_t i;
  17. if (!tabl)
  18. {
  19. if (!(tmp = (char **)ft_memalloc(sizeof(char *) * 2)))
  20. return (NULL);
  21. tmp[1] = 0;
  22. tmp[0] = ft_strdup(src);
  23. }
  24. else
  25. {
  26. i = -1;
  27. if (!(tmp = (char **)ft_memalloc(sizeof(char *) *
  28. (ft_tablen(tabl) + 2))))
  29. return (NULL);
  30. while (tabl[++i])
  31. tmp[i] = ft_strdup(tabl[i]);
  32. tmp[i] = ft_strdup(src);
  33. tmp[i + 1] = 0;
  34. ft_memdel2((void ***)&tabl);
  35. }
  36. return (tmp);
  37. }