wip_parsing
This commit is contained in:
41
libft/str/ft_strjoin.c
Normal file
41
libft/str/ft_strjoin.c
Normal file
@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/07/27 17:26:43 by madumerg #+# #+# */
|
||||
/* Updated: 2024/07/09 15:36:26 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
size_t len;
|
||||
size_t i;
|
||||
size_t j;
|
||||
char *str;
|
||||
|
||||
if (!s1)
|
||||
return (ft_strdup(s2));
|
||||
if (!s2)
|
||||
return (ft_strdup(s1));
|
||||
len = ft_strlen(s1) + ft_strlen(s2);
|
||||
str = malloc(sizeof(char) * (len + 1));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s1[i] != '\0')
|
||||
{
|
||||
str[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
j = 0;
|
||||
while (s2[j] != '\0')
|
||||
str[i++] = s2[j++];
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
Reference in New Issue
Block a user