-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strlcat.c
61 lines (53 loc) · 1.84 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
49
50
51
52
53
54
55
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tauer <tauer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/07 15:49:49 by tauer #+# #+# */
/* Updated: 2023/11/16 10:37:32 by tauer ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dest, const char *src, size_t size)
{
unsigned int dest_len;
unsigned int src_len;
unsigned int i;
unsigned int j;
src_len = ft_strlen(src);
if (!size)
return (src_len);
dest_len = ft_strlen(dest);
i = 0;
j = 0;
if (size < 1)
return (src_len + size);
while (dest[i] != '\0')
i++;
while (src[j] && i < size - 1)
dest[i++] = src[j++];
dest[i] = '\0';
if (size < dest_len)
return (size + src_len);
else
return (dest_len + src_len);
}
// #include <bsd/string.h>
// #include <stdio.h>
// int main(void)
// {
// int size = 1;
// char dest[10] = "01234";
// char src[] = "ABCD";
// strlcat(dest, src, size);
// printf("real : %s\n", dest);
// printf("%ld\n\n", strlcat(dest, src, size));
// char dest_mine[10] = "01234";
// char src_mine[] = "ABCD";
// ft_strlcat(dest_mine, src_mine, size);
// printf("mine : %s\n", dest_mine);
// printf("%d\n", ft_strlcat(dest_mine, src_mine, size));
// return (0);
// }