memccpy

홍민주·2021년 5월 30일
0

memccpy

- 함수 설명

The memccpy() function copies bytes from string src to string dst.
If the character c (as converted to an unsigned char) occurs in the string src, the copy stops and a pointer to the byte after the copy of c in the string dst is returned. Otherwise, n bytes are copied, and a NULL pointer is returned.

- 매개변수

변수명설명
dst복사되는 메모리의 첫번째 주소
src복사할 메모리의 첫번째 주소
csrc에서 만나면 복사를 중단할 char (unsigned char)
n복사할 길이 (byte 단위)

- 반환값

성공 : 복사가 끝난 후 dst의 다음 메모리 주소.
실패 : NULL

- 코드

void	*memccpy(void *dst, const void *src, int c, size_t n)
{
	size_t			i;
	unsigned char	*dst_ptr;
	unsigned char	*src_ptr;
	unsigned char	find;

	i = 0;
	find = c;
	dst_ptr = dst;
	src_ptr = (unsigned char *)src;
	while (i < n)
	{
		dst_ptr[i] = src_ptr[i];
		if (src_ptr[i] == find)
			return (dst + i + 1);
		i++;
	}
	return (0);
}
profile
백엔드 주니어 개발자 입니다~

0개의 댓글

관련 채용 정보