base struct
This commit is contained in:
38
lib/libft/srcs/str/ft_strjoin.c
Normal file
38
lib/libft/srcs/str/ft_strjoin.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/14 17:14:32 by nalebrun #+# #+# */
|
||||
/* Updated: 2024/11/25 16:16:11 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft.h"
|
||||
|
||||
char *ft_strjoin(const char *s1, const char *s2)
|
||||
{
|
||||
char *out;
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
|
||||
if (!s1 && !s2)
|
||||
return (NULL);
|
||||
if (!s1)
|
||||
return (ft_strdup(s2));
|
||||
if (!s2)
|
||||
return (ft_strdup(s1));
|
||||
out = ft_calloc(ft_strlen(s1) + ft_strlen(s2) + 1, sizeof(char));
|
||||
if (!out)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (s1[j])
|
||||
out[i++] = s1[j++];
|
||||
j = 0;
|
||||
while (s2[j])
|
||||
out[i++] = s2[j++];
|
||||
return (out);
|
||||
}
|
||||
Reference in New Issue
Block a user