memchr

홍민주·2021년 5월 30일
0

memchr

- 함수 설명

The memchr() function locates the first occurrence of c (converted to an unsigned char) in string s.

- 매개변수

변수명설명
s데이터를 찾을 메모리 시작 위치
c찾을 데이터 값 (unsigned char)
ns에서 찾을 범위 크기 (byte 단위)

- 반환값

성공 : c를 처음 찾은 위치
실패 : NULL

- 코드

void	*memchr(const void *s, int c, size_t n)
{
	unsigned char *s_ptr;
	unsigned char find;

	find = c;
	s_ptr = (unsigned char *)s;
	while (n--)
	{
		if (*s_ptr == find)
			return (s_ptr);
		s_ptr++;
	}
	return (0);
}
profile
백엔드 주니어 개발자 입니다~

0개의 댓글