skeletton untested project
This commit is contained in:
commit
6fc620e8f4
187 changed files with 6584 additions and 0 deletions
42
libft/ft_strjoin.c
Executable file
42
libft/ft_strjoin.c
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 12:14:45 by thrieg #+# #+# */
|
||||
/* Updated: 2025/02/16 19:04:47 by thrieg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
//returns NULL if any argument is null or if an allocation fails
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
char *ret;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
if (!s1 || !s2)
|
||||
return (NULL);
|
||||
ret = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
|
||||
if (!ret)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s1[i])
|
||||
{
|
||||
ret[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
j = 0;
|
||||
while (s2[j])
|
||||
{
|
||||
ret[i] = s2[j];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
ret[i] = '\0';
|
||||
return (ret);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue