wip_parsing
This commit is contained in:
38
libft/str/ft_strnstr.c
Normal file
38
libft/str/ft_strnstr.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 10:15:03 by madumerg #+# #+# */
|
||||
/* Updated: 2023/11/09 16:25:39 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *str, const char *to_find, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
if (!str)
|
||||
return (NULL);
|
||||
if (to_find[0] == '\0')
|
||||
return ((char *) &str[i]);
|
||||
while (str[i] && i < len)
|
||||
{
|
||||
while (str[i + j] == to_find[j] && i + j < len)
|
||||
{
|
||||
j++;
|
||||
if (to_find[j] == '\0')
|
||||
return ((char *) &str[i]);
|
||||
}
|
||||
j = 0;
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
Reference in New Issue
Block a user