diff options
| -rw-r--r-- | ft_strnstr.c | 18 | ||||
| -rw-r--r-- | ft_tolower.c | 16 | ||||
| -rw-r--r-- | ft_toupper.c | 6 |
3 files changed, 24 insertions, 16 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); diff --git a/ft_tolower.c b/ft_tolower.c index 5b5ee01..a6f5119 100644 --- a/ft_tolower.c +++ b/ft_tolower.c @@ -1,12 +1,12 @@ int ft_tolower(int c) { - unsigned char uc; - - uc = c; - /* if (c < -1) */ - /* return (c + 256); */ - - if (uc >= 'A' && uc <= 'Z') - return (uc - 'A' + 'a'); + if (c < -1) + return (c + 256); + if (c == -1) + return (-1); + if (c == 0) + return (0); + if (c >= 'A' && c <= 'Z') + return ('a' + c - 'A'); return (c); } diff --git a/ft_toupper.c b/ft_toupper.c index 7e85f8d..2832c28 100644 --- a/ft_toupper.c +++ b/ft_toupper.c @@ -2,6 +2,12 @@ int ft_toupper(int c) { + if (c < -1) + return (c + 256); + if (c == -1) + return (-1); + if (c == 0) + return (0); if (c >= 'a' && c <= 'z') return (c - 'a' + 'A'); return (c); |
