ft_memchr: initial implementation
This commit is contained in:
parent
b176bdaebe
commit
aad909fe23
3 changed files with 59 additions and 2 deletions
54
ft_memchr.c
Normal file
54
ft_memchr.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/16 14:01:28 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/16 14:05:38 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, t_size n)
|
||||
{
|
||||
t_size i;
|
||||
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
if (((const unsigned char *)s)[i] == (unsigned char)c)
|
||||
return ((void *)s + i);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *result;
|
||||
t_size cmp_len;
|
||||
|
||||
cmp_len = 5;
|
||||
if (argc > 2)
|
||||
{
|
||||
result = ft_memchr(argv[1], argv[2][0], cmp_len);
|
||||
if (result == 0)
|
||||
printf("(null)\n");
|
||||
else
|
||||
printf("%s\n", result);
|
||||
result = memchr(argv[1], argv[2][0], cmp_len);
|
||||
if (result == 0)
|
||||
printf("(null)\n");
|
||||
else
|
||||
printf("%s\n", result);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue