-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strlcat.c
48 lines (43 loc) · 1.59 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
42
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edegraev <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/09 11:11:17 by edegraev #+# #+# */
/* Updated: 2023/11/15 17:45:52 by edegraev ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dest, const char *src, size_t size)
{
size_t i;
size_t j;
size_t len;
if ((!dest || !src) && size == 0)
return (0);
i = ft_strlen(dest);
j = 0;
if (size < i)
return ((size_t)ft_strlen(src) + size);
while (size != 0 && src[j] != '\0' && i + j < size -1)
{
dest[i + j] = src[j];
j++;
}
dest[i + j] = '\0';
len = i + (size_t)ft_strlen(src);
return (len);
}
// #include <stdio.h>
// #include <string.h>
// int main()
// {
// char buffer[15] = "rrrrrrrrrrrrrrr";
// //char *my_string = "Bonjou toi";
// //ft_strlcat(buffer, my_string, 11);
// printf("%d\n", (int)ft_strlcat(buffer, "lorem ipsum dolor sit amet", 5));
// printf("%s\n", buffer);
// return (0);
// }