init
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rzy <ry@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/08/23 23:27:28 by rzy #+# #+# */
|
||||
/* Updated: 2026/08/23 23:33:18 by rzy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *haystack, const char *needle, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
if (!needle[0])
|
||||
return ((char *)(haystack));
|
||||
i = 0;
|
||||
while (i < n && haystack[i])
|
||||
{
|
||||
j = 0;
|
||||
while (i + j < n && needle[j] && haystack[i + j] == needle[j])
|
||||
++j;
|
||||
if (!needle[j])
|
||||
return ((char *)&haystack[i]);
|
||||
++i;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user