ft_strlcat: initial implementation
This commit is contained in:
parent
a7ffedf420
commit
870ce44765
3 changed files with 66 additions and 3 deletions
61
ft_strlcat.c
Normal file
61
ft_strlcat.c
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 16:00:39 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/15 16:17:34 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_size ft_strlcat(char *dst, const char *src, t_size size)
|
||||
{
|
||||
t_size dst_len;
|
||||
t_size src_len;
|
||||
t_size i;
|
||||
|
||||
dst_len = 0;
|
||||
while (dst[dst_len] != '\0')
|
||||
dst_len++;
|
||||
src_len = 0;
|
||||
while (src[src_len] != '\0')
|
||||
src_len++;
|
||||
if (size <= dst_len)
|
||||
return (size + src_len);
|
||||
i = 0;
|
||||
while (src[i] != '\0' && i < size - dst_len - 1)
|
||||
{
|
||||
dst[dst_len + i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dst[dst_len + i] = '\0';
|
||||
return (dst_len + src_len);
|
||||
}
|
||||
|
||||
/*
|
||||
#include <bsd/string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char dest1[40] = "Hi there, hello!!!!!";
|
||||
char dest2[40] = "Hi there, hello!!!!!";
|
||||
char *src = " Hello!";
|
||||
int res1;
|
||||
size_t res2;
|
||||
|
||||
res1 = ft_strlcat(dest1, src, 20);
|
||||
printf("mine:\t%u\t'%s'\n", res1, dest1);
|
||||
res2 = strlcat(dest2, src, 20);
|
||||
printf("lib:\t%zu\t'%s'\n", res2, dest2);
|
||||
res1 = ft_strlcat(dest1, src, 40);
|
||||
printf("mine:\t%u\t'%s'\n", res1, dest1);
|
||||
res2 = strlcat(dest2, src, 40);
|
||||
printf("lib:\t%zu\t'%s'\n", res2, dest2);
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue