62 lines
1.6 KiB
C
62 lines
1.6 KiB
C
|
|
/* ************************************************************************** */
|
||
|
|
/* */
|
||
|
|
/* ::: :::::::: */
|
||
|
|
/* ft_strnstr.c :+: :+: :+: */
|
||
|
|
/* +:+ +:+ +:+ */
|
||
|
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||
|
|
/* +#+#+#+#+#+ +#+ */
|
||
|
|
/* Created: 2024/10/16 15:38:24 by kcolin #+# #+# */
|
||
|
|
/* Updated: 2024/10/16 15:58:22 by kcolin ### ########.fr */
|
||
|
|
/* */
|
||
|
|
/* ************************************************************************** */
|
||
|
|
|
||
|
|
#include "libft.h"
|
||
|
|
|
||
|
|
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||
|
|
{
|
||
|
|
size_t i;
|
||
|
|
size_t j;
|
||
|
|
int found;
|
||
|
|
|
||
|
|
if (*little == '\0')
|
||
|
|
return ((char *)big);
|
||
|
|
i = 0;
|
||
|
|
while (big[i] != '\0' && i < len)
|
||
|
|
{
|
||
|
|
j = 0;
|
||
|
|
found = 1;
|
||
|
|
while (little[j] != '\0' && i + j < len)
|
||
|
|
{
|
||
|
|
if (little[j] != big[i + j])
|
||
|
|
{
|
||
|
|
found = 0;
|
||
|
|
break ;
|
||
|
|
}
|
||
|
|
j++;
|
||
|
|
}
|
||
|
|
if (found == 1 && little[j] == '\0')
|
||
|
|
return ((char *)big + i);
|
||
|
|
i++;
|
||
|
|
}
|
||
|
|
return (NULL);
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <bsd/string.h>
|
||
|
|
|
||
|
|
int main(int argc, char **argv)
|
||
|
|
{
|
||
|
|
size_t cmp_len;
|
||
|
|
|
||
|
|
cmp_len = 40;
|
||
|
|
if (argc > 2)
|
||
|
|
{
|
||
|
|
printf("mine: %s\nlib: %s\n",
|
||
|
|
ft_strnstr(argv[1], argv[2], cmp_len),
|
||
|
|
strnstr(argv[1], argv[2], cmp_len));
|
||
|
|
}
|
||
|
|
return (0);
|
||
|
|
}
|
||
|
|
*/
|