2024-10-16 14:21:59 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
|
|
|
|
/* 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"
|
|
|
|
|
|
2024-10-16 15:20:28 +02:00
|
|
|
void *ft_memchr(const void *s, int c, size_t n)
|
2024-10-16 14:21:59 +02:00
|
|
|
{
|
2024-10-16 15:20:28 +02:00
|
|
|
size_t i;
|
2024-10-16 14:21:59 +02:00
|
|
|
|
|
|
|
|
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;
|
2024-10-16 15:20:28 +02:00
|
|
|
size_t cmp_len;
|
2024-10-16 14:21:59 +02:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
*/
|