diff options
Diffstat (limited to 'ft_strnstr.c')
| -rw-r--r-- | ft_strnstr.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/ft_strnstr.c b/ft_strnstr.c index 2308a57..4109f2d 100644 --- a/ft_strnstr.c +++ b/ft_strnstr.c @@ -2,27 +2,29 @@ #include <string.h> #include "libft.h" +#include <stdio.h> char *ft_strnstr(const char *big, const char *little, size_t len) { size_t i; size_t j; - size_t min_len; + size_t little_len; - min_len = len > ft_strlen(little) ? ft_strlen(little) : len; - if (min_len == 0) + little_len = ft_strlen(little); + if (little_len == 0 || len == 0) return ((char*)big); i = 0; - while (big[i]) + while (i < len && big[i]) { j = 0; - while (little[j] && big[i + j]) + while (i + j < len && little[j] && big[i + j]) { + /* printf(" %lu", i + j); */ if (little[j] != big[i + j]) - break ; + break ; j++; - if (j == min_len) - return ((char*)(big + i)); } + if (j == little_len) + return ((char*)big + i); i++; } return (NULL); |
