/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlcpy.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: whaffman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/06 12:11:53 by whaffman #+# #+# */ /* Updated: 2024/06/10 11:13:34 by whaffman ### ########.fr */ /* */ /* ************************************************************************** */ #include 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