-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strlcat.c
More file actions
55 lines (51 loc) · 1.97 KB
/
ft_strlcat.c
File metadata and controls
55 lines (51 loc) · 1.97 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lcosta-g <lcosta-g@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/09 13:09:31 by lcosta-g #+# #+# */
/* Updated: 2024/10/14 13:42:38 by lcosta-g ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t dst_len;
size_t src_len;
size_t i;
dst_len = ft_strlen(dst);
src_len = ft_strlen(src);
if (size <= dst_len)
return (size + src_len);
i = 0;
while (src[i] && i < (size - dst_len - 1))
{
dst[dst_len + i] = src[i];
i++;
}
dst[dst_len + i] = '\0';
return (dst_len + src_len);
}
/*
#include <stdio.h>
int main(void)
{
char dst[50] = "--------------------";
printf("ft_strlcat(\"--------------------\", \"strlcat example\", 50)\n");
printf(" retorna %zu\n", ft_strlcat(dst, "strlcat example", 50));
printf(" dst = \"%s\"\n", dst);
printf("\n\n");
char dst2[20] = "--------";
printf("ft_strlcat(\"--------\", \"testing strlcat again\", 20)\n");
printf(" retorna %zu\n", ft_strlcat(dst2, "testing strlcat again", 20));
printf(" dst = \"%s\"\n", dst2);
printf("\n\n");
char dst3[] = "";
printf("ft_strlcat(\"\", \"empty dest test\", 0)\n");
printf(" retorna %zu\n", ft_strlcat(dst3, "empty dest test", 0));
printf(" dst = \"%s\"\n", dst3);
return (0);
}
*/