-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strchrjoin.c
54 lines (49 loc) · 1.47 KB
/
ft_strchrjoin.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
43
44
45
46
47
48
49
50
51
52
53
54
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchrjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rymuller <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/12/07 19:08:49 by rymuller #+# #+# */
/* Updated: 2018/12/10 12:23:00 by rymuller ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t charlen(char const *s, char c)
{
size_t i;
if (s != NULL)
{
i = 0;
while (s[i] != '\0' && s[i] != c)
i++;
return (i);
}
return (0);
}
char *ft_strchrjoin(char const *s1, char const *s2, char c)
{
size_t i;
size_t j;
size_t len;
char *res;
if (s1 != NULL && s2 != NULL)
{
len = ft_strlen(s1) + charlen(s2, c);
if (!(res = (char *)malloc(len + 1)))
return (NULL);
i = -1;
while (s1[++i])
res[i] = s1[i];
j = 0;
while (s2[j] && s2[j] != c)
{
res[i + j] = s2[j];
j++;
}
res[i + j] = '\0';
return (res);
}
return (NULL);
}