ft_strlcpy

one·2021년 1월 7일
0

✅strlcpy

  • Copy a NULL terminated string into a sized buffer
  • dstsrcsize - 1 만큼 복사.

💾함수 원형

size_t	strlcpy(char *dst, const char *src, size_t dstsize);

💻Parameters

  • dst : Where to copy the string to
  • src : Where to copy the string from
  • dstsize : size of destination buffer

💻Return value

  • src의 길이

💾함수 구현

#include "libft.h"

size_t	ft_strlcpy(char *dst, const char *src, size_t dstsize)
{
	size_t	src_len;
	size_t	i;

	src_len = 0;
	i = 0;
	while(src[src_len] != '\0')
		src_len++;
	if (dstsize == 0)
		return (src_len);
	while (src[i] != '\0' && i < (dstsize - 1))
	{
		dst[i] = src[i];
		i++;
	}
	dst[i] = '\0';
	return (src_len);
}
profile
늘 호기심을 갖고, 새로운 것에 도전할 것.

0개의 댓글