-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strlcat.c
56 lines (50 loc) · 1.56 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ana-lda- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/11 19:04:27 by ana-lda- #+# #+# */
/* Updated: 2024/04/30 14:53:04 by ana-lda- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/** @brief anexa a string scr ao final da dest e conta o tamanho
do resultado da concatenacao de ambas
*/
size_t ft_strlcat(char *dest, const char *src, size_t size)
{
size_t d;
size_t s;
unsigned int i;
unsigned int j;
d = ft_strlen(dest);
s = ft_strlen(src);
i = d;
j = 0;
while (src[j] && i + 1 < size)
{
dest[i] = src[j];
i++;
j++;
}
dest[i] = '\0';
if (size <= d)
{
return (size + s);
}
return (d + s);
}
/*#include <stdio.h>
#include <string.h>
int main(void)
{
const char src[50] = "world";
char dest[50] = "hello ";
unsigned int i;
i = 10;
printf("ft_strlcat = %zu\n", ft_strlcat(dest, src, i));
printf("%s\n", dest);
return (0);
}*/