ft_strnstr.c
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* ft_strnstr.c :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: ll-hotel <ll-hotel@student.42lyon.fr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2023/11/07 16:02:29 by ll-hotel #+# #+# */ 9 /* Updated: 2024/02/23 03:42:52 by ll-hotel ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 char *ft_strnstr(const char *big, const char *little, unsigned long long len) 14 { 15 unsigned long long i; 16 unsigned long long j; 17 unsigned long long lenlil; 18 19 if (*little == 0) 20 return ((char *)big); 21 lenlil = 0; 22 while (big && little[lenlil]) 23 lenlil++; 24 if (len < lenlil) 25 return (0); 26 i = 0; 27 while (big[i] && i < len - lenlil + 1) 28 { 29 j = 0; 30 while (i + j < len && little[j] && big[i + j] == little[j]) 31 j++; 32 if (little[j] == 0) 33 return ((char *)(big + i)); 34 i += j + big[i] != 0; 35 } 36 return (0); 37 }