-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin.c
More file actions
70 lines (60 loc) · 1.72 KB
/
Copy pathft_strjoin.c
File metadata and controls
70 lines (60 loc) · 1.72 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atok <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/19 10:57:03 by atok #+# #+# */
/* Updated: 2022/10/19 10:57:03 by atok ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t jstrlen(char const *str)
{
int len;
len = 0;
while (str[len] != 0x00)
len++;
return (len);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *ss;
int dl;
int sl;
if (s1 == 0x00 || s2 == 0x00)
return (0);
ss = (char *)malloc((jstrlen(s1) + jstrlen(s2) + 1) * sizeof(char));
if (ss == NULL)
return (NULL);
dl = 0;
while (s1[dl] != 0x00)
{
ss[dl] = s1[dl];
dl++;
}
sl = 0;
while (s2[sl] != 0x00)
{
ss[dl] = s2[sl];
sl++;
dl++;
}
ss[dl] = 0x00;
return (ss);
}
/* int main (void)
{
char s1[] = "front";
char s2[] = "back";
char *ss = ft_strjoin(s1,s2);
// printf(":%s:\n",ft_strjoin(s1,s2));
printf(":%s:\n",ss);
free(ss);
return (0);
} */
/* malloc s1 & s2 +1
then proceed with strcat
without malloc will seg falt
*/