From c378c27ef99a2b585ffccc6b76e6688f50a7f63f Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Mon, 14 Aug 2023 13:45:12 +0200 Subject: [PATCH] Added a couple of wanted functions. Also added 2 additional functions - islower and isupper. These functions naturaly fit in and are used for more readible implementation of other functions. Each .c file includes the library header libft.h (libft.h is not added in this commit). --- ft_bzero.c | 20 ++++++++++++++++++++ ft_isalnum.c | 18 ++++++++++++++++++ ft_isalpha.c | 18 ++++++++++++++++++ ft_isdigit.c | 18 ++++++++++++++++++ ft_islower.c | 18 ++++++++++++++++++ ft_isupper.c | 18 ++++++++++++++++++ ft_memcpy.c | 24 ++++++++++++++++++++++++ ft_memmove.c | 32 ++++++++++++++++++++++++++++++++ ft_memset.c | 21 +++++++++++++++++++++ ft_strlcat.c | 42 ++++++++++++++++++++++++++++++++++++++++++ ft_strlcpy.c | 29 +++++++++++++++++++++++++++++ ft_strlen.c | 24 ++++++++++++++++++++++++ 12 files changed, 282 insertions(+) create mode 100644 ft_bzero.c create mode 100644 ft_isalnum.c create mode 100644 ft_isalpha.c create mode 100644 ft_isdigit.c create mode 100644 ft_islower.c create mode 100644 ft_isupper.c create mode 100644 ft_memcpy.c create mode 100644 ft_memmove.c create mode 100644 ft_memset.c create mode 100644 ft_strlcat.c create mode 100644 ft_strlcpy.c create mode 100644 ft_strlen.c diff --git a/ft_bzero.c b/ft_bzero.c new file mode 100644 index 0000000..9346d4b --- /dev/null +++ b/ft_bzero.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/14 13:38:08 by ljiriste #+# #+# */ +/* Updated: 2023/08/14 13:38:32 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + ft_memset(s, 0, n); + return ; +} diff --git a/ft_isalnum.c b/ft_isalnum.c new file mode 100644 index 0000000..fd9ed56 --- /dev/null +++ b/ft_isalnum.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/14 13:02:16 by ljiriste #+# #+# */ +/* Updated: 2023/08/14 13:34:41 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + return (ft_isdigit(c) || ft_isalpha(c)); +} diff --git a/ft_isalpha.c b/ft_isalpha.c new file mode 100644 index 0000000..c3a3ebc --- /dev/null +++ b/ft_isalpha.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/14 13:32:19 by ljiriste #+# #+# */ +/* Updated: 2023/08/14 13:32:33 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalpha(int c) +{ + return (ft_isupper(c) || ft_islower(c)); +} diff --git a/ft_isdigit.c b/ft_isdigit.c new file mode 100644 index 0000000..6df7e2c --- /dev/null +++ b/ft_isdigit.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/14 13:32:47 by ljiriste #+# #+# */ +/* Updated: 2023/08/14 13:33:02 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isdigit(int c) +{ + return ('0' <= c && c <= '9'); +} diff --git a/ft_islower.c b/ft_islower.c new file mode 100644 index 0000000..ebcf47d --- /dev/null +++ b/ft_islower.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_islower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/14 13:31:47 by ljiriste #+# #+# */ +/* Updated: 2023/08/14 13:32:05 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_islower(int c) +{ + return ('a' <= c && c <= 'z'); +} diff --git a/ft_isupper.c b/ft_isupper.c new file mode 100644 index 0000000..4a9acd2 --- /dev/null +++ b/ft_isupper.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/14 13:31:05 by ljiriste #+# #+# */ +/* Updated: 2023/08/14 13:31:31 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_isupper(int c) +{ + return ('A' <= c && c <= 'Z'); +} diff --git a/ft_memcpy.c b/ft_memcpy.c new file mode 100644 index 0000000..e4d2b2c --- /dev/null +++ b/ft_memcpy.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/14 13:35:59 by ljiriste #+# #+# */ +/* Updated: 2023/08/14 13:36:20 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + while (n > 0) + { + --n; + *((unsigned char *)dest + n) = *((unsigned char *)src + n); + } + return (dest); +} diff --git a/ft_memmove.c b/ft_memmove.c new file mode 100644 index 0000000..83692d1 --- /dev/null +++ b/ft_memmove.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/14 13:36:32 by ljiriste #+# #+# */ +/* Updated: 2023/08/14 13:37:03 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void *ft_memmove(void *dest, const void *src, size_t n) +{ + size_t i; + + if (dest > src) + ft_memcpy(dest, src, n); + else if (dest < src) + { + i = 0; + while (i < n) + { + *((unsigned char *)dest + i) = *((unsigned char *)src + i); + ++i; + } + } + return (dest); +} diff --git a/ft_memset.c b/ft_memset.c new file mode 100644 index 0000000..bfa0468 --- /dev/null +++ b/ft_memset.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/14 13:13:22 by ljiriste #+# #+# */ +/* Updated: 2023/08/14 13:38:38 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void *ft_memset(void *s, int c, size_t n) +{ + while (n > 0) + *((unsigned char *)s + (--n)) = c; + return (s); +} diff --git a/ft_strlcat.c b/ft_strlcat.c new file mode 100644 index 0000000..ed6e7b5 --- /dev/null +++ b/ft_strlcat.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/12 17:32:33 by ljiriste #+# #+# */ +/* Updated: 2023/08/14 13:39:39 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +size_t ft_strlcat(char *dst, char *src, size_t size) +{ + size_t length; + + length = 0; + while (*dst != '\0' && size > 1) + { + ++dst; + ++length; + --size; + } + while (*src != '\0' && size > 1) + { + *dst = *src; + ++src; + ++dst; + ++length; + --size; + } + while (size > 0) + { + *dst = '\0'; + ++dst; + --size; + } + return (length); +} diff --git a/ft_strlcpy.c b/ft_strlcpy.c new file mode 100644 index 0000000..3f1d16c --- /dev/null +++ b/ft_strlcpy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/11 17:28:43 by ljiriste #+# #+# */ +/* Updated: 2023/08/14 13:29:38 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +size_t ft_strlcpy(char *dst, char *src, size_t size) +{ + size_t i; + + i = 0; + while (*src != '\0' && i + 1 < size) + { + dst[i] = src[i]; + ++i; + } + if (size > 0) + dst[i] = '\0'; + return (ft_strlen(src)); +} diff --git a/ft_strlen.c b/ft_strlen.c new file mode 100644 index 0000000..f4ae6c7 --- /dev/null +++ b/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/08/14 13:40:59 by ljiriste #+# #+# */ +/* Updated: 2023/08/14 13:41:35 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +size_t ft_strlen(const char *s) +{ + size_t len; + + len = 0; + while (s[len] != '\0') + ++len; + return len; +} -- 2.30.2