-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strjoin_new.c
42 lines (39 loc) · 1.38 KB
/
ft_strjoin_new.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin_new.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: matlopes <matlopes@student.42.rio> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 14:07:11 by matlopes #+# #+# */
/* Updated: 2023/11/27 14:07:11 by matlopes ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin_new(char *old, char *str)
{
char *pointer;
int counter;
counter = 0;
pointer = malloc((ft_strlen(old) + ft_strlen(str) + 1) * sizeof(char));
if (!pointer)
return (NULL);
if (old)
{
while (old[counter])
{
pointer[counter] = old[counter];
counter++;
}
free(old);
}
while (*str)
pointer[counter++] = *str++;
pointer[counter] = '\0';
if (!*pointer)
{
free(pointer);
return (NULL);
}
return (pointer);
}