39 lines
1.2 KiB
C
39 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strjoin.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/11/06 13:52:21 by dgaillet #+# #+# */
|
|
/* Updated: 2025/11/06 13:56:29 by dgaillet ### ########lyon.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strjoin(char const *s1, char const *s2)
|
|
{
|
|
char *str;
|
|
int i;
|
|
int j;
|
|
|
|
str = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
|
|
if (!str)
|
|
return (NULL);
|
|
i = 0;
|
|
j = 0;
|
|
while (s1[i])
|
|
{
|
|
str[i] = s1[i];
|
|
i++;
|
|
}
|
|
while (s2[j])
|
|
{
|
|
str[i + j] = s2[j];
|
|
j++;
|
|
}
|
|
str[i + j] = '\0';
|
|
return (str);
|
|
}
|