-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
41 lines (38 loc) · 1.41 KB
/
ft_strlcat.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thuy-ngu <thuy-ngu@student.42lisboa.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/08 14:47:44 by thuy-ngu #+# #+# */
/* Updated: 2023/10/14 17:44:38 by thuy-ngu ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t srclen;
size_t dstlen;
size_t i;
i = 0;
srclen = ft_strlen(src);
dstlen = ft_strlen(dst);
if (size == 0 || size < dstlen)
return (srclen + size);
while (src[i] && (dstlen + i) < (size - 1))
{
dst[dstlen + i] = src[i];
i++;
}
dst[dstlen + i] = '\0';
return (dstlen + srclen);
}
/*int main()
{
char dst[] = "is";
char src[] = "something";
printf("%zu\n", sizeof(dst));
printf("%zu\n", ft_strlcat(dst, src, sizeof(dst)));
printf("%s\n", dst);
}*/