-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
35 lines (31 loc) · 1.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mlindenm <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/31 19:00:11 by mlindenm #+# #+# */
/* Updated: 2023/10/19 17:44:11 by mlindenm ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*This function appends a string (src) to another string (dst) while ensuring
the combined result does not exceed a specified length (n) and returns the
final length of the concatenated string.*/
size_t ft_strlcat(char *dst, const char *src, size_t n)
{
size_t dst_len;
size_t i;
dst_len = ft_strlen(dst);
if (n <= dst_len)
return (ft_strlen(src) + n);
i = 0;
while ((dst_len + i) < (n - 1) && src[i] != '\0')
{
dst[dst_len + i] = src[i];
i++;
}
dst[dst_len + i] = '\0';
return (ft_strlen(src) + dst_len);
}