mirror of
https://github.com/guezoloic/libft.git
synced 2026-01-25 10:34:16 +00:00
add ft_memchr function
This commit is contained in:
18
ft_memchr.c
Normal file
18
ft_memchr.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
const unsigned char *ptr;
|
||||
|
||||
i = 0;
|
||||
ptr = (const unsigned char *)s;
|
||||
while (i < n)
|
||||
{
|
||||
if ((unsigned char)c == ptr[i])
|
||||
return ((void*)(ptr+i));
|
||||
i++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user