-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strlcat.c
More file actions
56 lines (47 loc) · 1.63 KB
/
ft_strlcat.c
File metadata and controls
56 lines (47 loc) · 1.63 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atiampae <atiampae@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/28 13:32:28 by atiampae #+# #+# */
/* Updated: 2022/10/30 22:20:42 by atiampae ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
size_t srclen;
size_t dstlen;
size_t i;
if (dstsize == 0)
return (0);
dstlen = ft_strlen(dst);
srclen = ft_strlen(src);
if (dstsize < dstlen + 1)
return (srclen + dstsize);
i = 0;
while (src[i] && (dstlen + i + 1) < dstsize)
{
dst[dstlen + i] = src[i];
i++;
}
dst[dstlen + i] = 0;
return (srclen + dstlen);
}
/*
#include<stdio.h>
#include<string.h>
int main(void)
{
char dst1[1000] = "Hello"; //dstlen = 5
char src1[] = "World"; // srclen = 5
char dst2[1000] = "Hello";
char src2[] = "World";
size_t len = 1; // dstsize = 1
printf("%lu\n",ft_strlcat(dst1,src1,len));
printf("%lu\n",strlcat(dst2,src2,len));
printf("%s\n",dst1);
printf("%s\n",dst2);
}*/