mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-14 00:08:47 +02:00
「✨」 feat(libft): added a very cool feature !
This commit is contained in:
35
libft/str/ft_strnstr.c
Normal file
35
libft/str/ft_strnstr.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 16:02:17 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:48:22 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
if (!big && len == 0)
|
||||
return (NULL);
|
||||
if (*little == '\0' || little == big)
|
||||
return ((char *)big);
|
||||
while (i < len && big[i])
|
||||
{
|
||||
j = 0;
|
||||
while (big[i + j] == little[j] && little[j] && big[i] && i + j < len)
|
||||
j++;
|
||||
if (little[j] == 0)
|
||||
return ((char *)big + i);
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
Reference in New Issue
Block a user