Browse Source

[enh] strjoinf: rework:
- use ft_strjoin().
- fix ternary condition to free string.
- add comments.

Moul 3 years ago
parent
commit
cfe3b5f62e
1 changed files with 9 additions and 7 deletions
  1. 9 7
      src/ft_strjoinf.c

+ 9 - 7
src/ft_strjoinf.c

@@ -6,22 +6,24 @@
 /*   By: mazimi <mazimi@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2014/11/10 17:27:47 by mazimi            #+#    #+#             */
-/*   Updated: 2015/06/25 16:02:57 by mazimi           ###   ########.fr       */
+/*   Updated: 2017/01/30 17:06:22 by mazimi           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "../libft.h"
 
+/*
+** p: free strings
+** 1 for first string, 2 for snd string
+** 3 to free both strings
+*/
+
 char	*ft_strjoinf(char const *s1, char const *s2, int p)
 {
 	char	*str;
 
-	if (s1 == NULL || s2 == NULL)
-		return (NULL);
-	str = ft_strnew(ft_strlen(s1) + ft_strlen(s2));
-	ft_strcpy(str, s1);
-	str = ft_strcat(str, s2);
-	(p == 1 && p == 3) ? ft_strdel((char **)&s1) : ft_strdel((char **)&s2);
+	str = ft_strjoin(s1, s2);
+	(p == 1 || p == 3) ? ft_strdel((char **)&s1) : ft_strdel((char **)&s2);
 	if (p == 3)
 		ft_strdel((char**)&s2);
 	return (str);