mirror of
https://github.com/Ladebeze66/libft.git
synced 2025-12-13 12:46:55 +01:00
40 lines
1.3 KiB
C
Executable File
40 lines
1.3 KiB
C
Executable File
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strjoin.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/02/13 16:54:51 by fgras-ca #+# #+# */
|
|
/* Updated: 2023/03/13 13:58:13 by fgras-ca ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
char *ft_strjoin(char const *s1, char const *s2)
|
|
{
|
|
char *new_s;
|
|
size_t i;
|
|
size_t j;
|
|
|
|
if (!s1 || !s2)
|
|
return (0);
|
|
new_s = (char *)malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
|
|
if (!new_s)
|
|
return (0);
|
|
i = 0;
|
|
j = 0;
|
|
while (s1[i])
|
|
{
|
|
new_s[j] = s1[i];
|
|
i++;
|
|
j++;
|
|
}
|
|
i = 0;
|
|
while (s2[i])
|
|
new_s[j++] = s2[i++];
|
|
new_s[j] = '\0';
|
|
return (new_s);
|
|
}
|