ft_memchr
Subject
MEMCHR(3) (simplified)
NAME
memchr -- locate byte in byte string
SYNOPSIS
void *memchr(const void *s, int c, size_t n);
DESCRIPTION
the memchr() function locates the first occurence of c (convered to an unsigned char) in string s.
RETURN VALUES
The memchr() function returns a pointer to the byte located, or NULL if no such byte exists within n bytes.Understandable explanation
Hints
void *ft_memchr(const void *s, int c, size_t n)
{
/* as said in the man, the search is done for c converted to
* an unsigned char, so we have to convert both c and s to
* unsigned char
*/
/* loop over the byte string until our counter is equal to n */
/* compare the current byte to c */
/* if they are the same, return the address of this byte as a
* void *
*/
/* if we searched n bytes and didn't find what we were looking for
* return NULL
*/
/* as you can see, this is very close to the strchr and strrchr
* functions, so take a look at these before looking at the
* solution
*/
}Commented solution
Last updated