piscine/c02/ex10/ft_strlcpy.c
Willem Haffmans 607ce08c18 all
2024-09-10 00:18:01 +02:00

59 lines
1.6 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/06 12:11:53 by whaffman #+# #+# */
/* Updated: 2024/06/10 11:13:34 by whaffman ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
int ft_strlen(char *str)
{
int result;
result = 0;
while (str[result])
{
result++;
}
return (result);
}
unsigned int ft_strlcpy(char *dest, char *src, unsigned int size)
{
unsigned int i;
unsigned int result;
i = 0;
while (src[i] && i < size - 1)
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
result = ft_strlen(src);
return (result);
}
#ifdef DEBUG
int main(void)
{
char src[13];
char dest[13];
int result;
ft_strlcpy(&src[0], "hello, world!", 13);
result = ft_strlcpy(&dest[0], "HELLO, WORLD!", 13);
printf("%d: %s\n", result, &dest[0]);
result = ft_strlcpy(&dest[0], &src[0], 13);
printf("%d: %s\n", result, &dest[0]);
return (0);
}
#endif