-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strlcat.c
61 lines (55 loc) · 1.58 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: davgalle <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 15:17:37 by davgalle #+# #+# */
/* Updated: 2023/07/19 16:39:13 by davgalle ### ########.fr */
/* */
/* ************************************************************************** */
#include<unistd.h>
#include<stdio.h>
#include<string.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}
unsigned int ft_strlcat(char *dest, char *src, unsigned int size)
{
unsigned int i;
unsigned int j;
unsigned int dlen;
unsigned int slen;
i = 0;
j = 0;
while (dest[j] != '\0')
j++;
dlen = j;
slen = ft_strlen(src);
if (size == 0 || size <= dlen)
return (slen + size);
while (src[i] != '\0' && i < size - dlen -1)
{
dest[j] = src[i];
i++;
j++;
}
dest[j] = '\0';
return (dlen + slen);
}
/*
int main(void)
{
char src[]= "david es";
char dest[]= "un tipo molon";
ft_strlcat(dest, src, 7);
int x = ft_strlcat(dest, src, 7);
printf("%d", x);
return 0;
}*/