-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strlcat.c
More file actions
47 lines (43 loc) · 1.49 KB
/
ft_strlcat.c
File metadata and controls
47 lines (43 loc) · 1.49 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sparth <sparth@student.42heilbronn.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/09 14:01:12 by sparth #+# #+# */
/* Updated: 2023/10/11 10:42:51 by sparth ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
size_t src_len;
size_t dst_len;
size_t i;
src_len = 0;
dst_len = 0;
i = 0;
while (src[src_len] != '\0')
src_len++;
while (dst[dst_len] != '\0')
dst_len++;
while (dstsize - i > dst_len + 1 && src[i] != '\0')
{
dst[dst_len + i] = src[i];
i++;
}
dst[dst_len + i] = '\0';
if (dstsize > dst_len)
return (src_len + dst_len);
else
return (src_len + dstsize);
}
// int main()
// {
// char dst[20] = "012345";
// char src[] = "6789";
// printf("%lu\n", ft_strlcat(dst, src, 5));
// printf("%s\n", dst);
// return (0);
// }