base c lib without external lib

This commit is contained in:
David Gailleton
2025-11-05 19:25:22 +01:00
parent e06b98052a
commit 697e044d7e
19 changed files with 445 additions and 13 deletions

31
ft_strnstr.c Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 18:05:52 by dgaillet #+# #+# */
/* Updated: 2025/11/05 19:07:15 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t little_len;
size_t i;
i = 0;
little_len = ft_strlen(little);
if (!little[0])
return ((char *) big);
while ((len - i) < little_len)
{
if (!ft_strncmp(&big[i], little, little_len))
return ((char *) &big[i]);
i++;
}
return (NULL);
}