ft_charjoin.c 1.2 KB

123456789101112131415161718192021222324252627282930
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_charjoin.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@students.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2016/07/23 03:06:18 by bchanot #+# #+# */
  9. /* Updated: 2016/10/16 22:14:39 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "libft.h"
  13. #include <stdlib.h>
  14. char *ft_charjoin(char const *s1, char const c)
  15. {
  16. char *str;
  17. int cpt;
  18. if (!s1 || !c)
  19. return (NULL);
  20. if (!(str = ft_strnew(ft_strlen(s1) + 1)))
  21. return (NULL);
  22. str = ft_strcpy(str, (char *)s1);
  23. cpt = ft_strlen(str);
  24. str[cpt] = c;
  25. str[cpt + 1] = '\0';
  26. return (str);
  27. }