diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-29 13:27:25 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-29 13:27:25 +0200 |
| commit | 009780065032aa23c6d72dd7ab02adb481a7c76d (patch) | |
| tree | 720fc692813d75019b30b78e980ff4a7dd3ffac0 | |
| parent | 5b653ccffdc33c8774697a93cad0b499b88dca71 (diff) | |
| download | libft-009780065032aa23c6d72dd7ab02adb481a7c76d.tar.gz libft-009780065032aa23c6d72dd7ab02adb481a7c76d.tar.bz2 libft-009780065032aa23c6d72dd7ab02adb481a7c76d.zip | |
part 1 pass except ft_isalnum (why??)
| -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); |
