ft_memccpy

one·2021년 1월 4일
0

✅memccpy

  • The memccpy() function copies no more than Size bytes from memmory area Src to memory area Dst, stopping when the character Val is found.

    if the memory areas overlap, the results are undefined.
  • copy string until character found
  • Src의 값들을 Size만큼 복사, 복사하는 과정에서 Val을 찾게되면 중단.

💾함수 원형

void *memccpy(void *Dst, const void *Src, int Val, size_t Size)

💻Parameters

  • void *Dst : 복사될 지점
  • const void *Src : 복사할 내용
  • int Val : 복사를 멈출 문자
  • size_t Size : 복사할 데이터의 바이트 수

💻Return value

  • Val을 찾으면 Val다음 주소값을 반환
  • Src의 값에서 Size만큼 중 Val을 찾지 못하면 Null을 반환

💾함수 구현

#include "libft.h"

void* ft_memccpy(void* dst, const void* src, int c, size_t n)
{
	unsigned char* tmp;
	unsigned char* str;
	size_t i;

	tmp = (unsigned char*)dst;
	str = (unsigned char*)src;
	i = 0;
	while (i < n)
	{
		tmp[i] = str[i];
		if (str[i] == (unsigned char)c)
			return ((void*)dst + i + 1);
		i++;
	}
	return (0);
}
profile
늘 호기심을 갖고, 새로운 것에 도전할 것.

0개의 댓글