aboutsummaryrefslogtreecommitdiff
path: root/lib/libft/ft_strjoin.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libft/ft_strjoin.c')
-rw-r--r--lib/libft/ft_strjoin.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/lib/libft/ft_strjoin.c b/lib/libft/ft_strjoin.c
index 5c0bf41..2cf68ea 100644
--- a/lib/libft/ft_strjoin.c
+++ b/lib/libft/ft_strjoin.c
@@ -6,41 +6,41 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 10:15:33 by dkaiser #+# #+# */
-/* Updated: 2025/01/22 00:27:04 by chuhlig ### ########.fr */
+/* Updated: 2025/01/25 12:55:14 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
-// static int copy_str(char *dst, const char *src)
-// {
-// int i;
-
-// i = 0;
-// while (src[i])
-// {
-// dst[i] = src[i];
-// i++;
-// }
-// return (i);
-// }
+static int copy_str(char *dst, const char *src)
+{
+ int i;
+
+ i = 0;
+ while (src[i])
+ {
+ dst[i] = src[i];
+ i++;
+ }
+ return (i);
+}
-char *ft_strjoin(const char *s1, const char *s2)
+char *ft_strjoin(char const *s1, char const *s2)
{
- char *joined_str;
- size_t len1;
- size_t len2;
-
- if (!s1 || !s2)
- return (NULL);
- len1 = strlen(s1);
- len2 = strlen(s2);
- joined_str = malloc(len1 + len2 + 1);
- if (!joined_str)
- return (NULL);
- strcpy(joined_str, s1);
- strcat(joined_str, s2);
- return (joined_str);
+ int len;
+ char *result;
+
+ len = ft_strlen(s1) + ft_strlen(s2);
+ result = malloc(len + 1);
+ if (result)
+ {
+ result[len] = '\0';
+ len = copy_str(result, s1);
+ len = copy_str(result + len, s2);
+ return (result);
+ }
+ else
+ return (0);
}
/* #include <stdio.h> */