Libft
42 Libft library documentation
Loading...
Searching...
No Matches
ft_memchr.c File Reference
#include <stdlib.h>
+ Include dependency graph for ft_memchr.c:

Go to the source code of this file.

Functions

void * ft_memchr (const void *s, int c, size_t n)
 Scans a memory area for a byte value.
 

Function Documentation

◆ ft_memchr()

void * ft_memchr ( const void *  s,
int  c,
size_t  n 
)

Scans a memory area for a byte value.

Parameters
sPointer to the memory area.
cByte value to search for.
nNumber of bytes to inspect.
Returns
Pointer to the first matching byte, or NULL if not found.

Definition at line 23 of file ft_memchr.c.

24{
25 const unsigned char *ptr;
26
27 ptr = (const unsigned char *)s;
28 while (n--)
29 {
30 if (*ptr == (unsigned char)c)
31 return ((void *)ptr);
32 ptr++;
33 }
34 return (NULL);
35}