summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Kaiser2024-03-10 13:37:45 +0100
committerDominik Kaiser2024-03-10 13:37:45 +0100
commit4e19b82398e0cfaa3ca0b9f68772c88d103ff6ea (patch)
treee25f459959a69578322529aca6d2a02cb2d3dfcf
parent3c90d29fe5bf9ba6da090cd59c8c139d269f8bd4 (diff)
downloadlibft-4e19b82398e0cfaa3ca0b9f68772c88d103ff6ea.tar.gz
libft-4e19b82398e0cfaa3ca0b9f68772c88d103ff6ea.zip
Complete missing functions and add header
-rw-r--r--Makefile36
-rw-r--r--ft_atoi.c4
-rw-r--r--ft_bzero.c4
-rw-r--r--ft_calloc.c4
-rw-r--r--ft_isalnum.c4
-rw-r--r--ft_isalpha.c4
-rw-r--r--ft_isdigit.c4
-rw-r--r--ft_isprint.c4
-rw-r--r--ft_memchr.c4
-rw-r--r--ft_memcmp.c4
-rw-r--r--ft_memcpy.c4
-rw-r--r--ft_memmove.c4
-rw-r--r--ft_memset.c4
-rw-r--r--ft_putchar_fd.c4
-rw-r--r--ft_putendl_fd.c4
-rw-r--r--ft_putstr_fd.c4
-rw-r--r--ft_strchr.c17
-rw-r--r--ft_strdup.c19
-rw-r--r--ft_strjoin.c4
-rw-r--r--ft_strlcat.c4
-rw-r--r--ft_strlcpy.c4
-rw-r--r--ft_strlen.c4
-rw-r--r--ft_strncmp.c4
-rw-r--r--ft_strnstr.c17
-rw-r--r--ft_strrchr.c4
-rw-r--r--ft_strtrim.c4
-rw-r--r--ft_substr.c25
-rw-r--r--ft_tolower.c4
-rw-r--r--ft_toupper.c4
-rw-r--r--libft.h10
30 files changed, 143 insertions, 77 deletions
diff --git a/Makefile b/Makefile
index 3920b81..8759efa 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,41 @@ NAME=libft.a
CC=cc
CFLAGS=-Wall -Wextra -Werror
-SRC_FILES = $(wildcard *.c)
+SRC_FILES = ft_atoi.c \
+ ft_bzero.c \
+ ft_calloc.c \
+ ft_isalnum.c \
+ ft_isalpha.c \
+ ft_isascii.c \
+ ft_isdigit.c \
+ ft_isprint.c \
+ ft_itoa.c \
+ ft_memchr.c \
+ ft_memcmp.c \
+ ft_memcpy.c \
+ ft_memmove.c \
+ ft_memset.c \
+ ft_putchar_fd.c \
+ ft_putendl_fd.c \
+ ft_putnbr_fd.c \
+ ft_putstr_fd.c \
+ ft_split.c \
+ ft_strchr.c \
+ ft_strdup.c \
+ ft_striteri.c \
+ ft_strjoin.c \
+ ft_strlcat.c \
+ ft_strlcpy.c \
+ ft_strlen.c \
+ ft_strmapi.c \
+ ft_strncmp.c \
+ ft_strnstr.c \
+ ft_strrchr.c \
+ ft_strtrim.c \
+ ft_substr.c \
+ ft_tolower.c \
+ ft_toupper.c \
+
OBJ_FILES = $(SRC_FILES:.c=.o)
diff --git a/ft_atoi.c b/ft_atoi.c
index 568a616..90200fb 100644
--- a/ft_atoi.c
+++ b/ft_atoi.c
@@ -6,10 +6,12 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 16:25:27 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 14:04:02 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:17:19 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "libft.h"
+
int ft_atoi(const char *str)
{
int result;
diff --git a/ft_bzero.c b/ft_bzero.c
index 2f77d78..78af51a 100644
--- a/ft_bzero.c
+++ b/ft_bzero.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 10:57:36 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 12:48:25 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:14:10 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <string.h>
+#include "libft.h"
void ft_bzero(void *s, size_t n)
{
diff --git a/ft_calloc.c b/ft_calloc.c
index 5baf8f1..2b711d9 100644
--- a/ft_calloc.c
+++ b/ft_calloc.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 19:45:56 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 16:34:30 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:17:31 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <stdlib.h>
+#include "libft.h"
void *ft_calloc(size_t count, size_t size)
{
diff --git a/ft_isalnum.c b/ft_isalnum.c
index 4de4a63..d705500 100644
--- a/ft_isalnum.c
+++ b/ft_isalnum.c
@@ -6,10 +6,12 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/04 21:14:49 by dkaiser #+# #+# */
-/* Updated: 2024/03/04 21:17:16 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:10:50 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "libft.h"
+
int ft_isalnum(int c)
{
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0'
diff --git a/ft_isalpha.c b/ft_isalpha.c
index 64d4b9a..054d96c 100644
--- a/ft_isalpha.c
+++ b/ft_isalpha.c
@@ -6,10 +6,12 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/04 19:59:23 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 13:10:30 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:10:10 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "libft.h"
+
int ft_isalpha(int c)
{
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
diff --git a/ft_isdigit.c b/ft_isdigit.c
index 273bfa3..2601fee 100644
--- a/ft_isdigit.c
+++ b/ft_isdigit.c
@@ -6,10 +6,12 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/04 21:07:03 by dkaiser #+# #+# */
-/* Updated: 2024/03/04 21:18:00 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:10:23 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "libft.h"
+
int ft_isdigit(int c)
{
if (c >= '0' && c <= '9')
diff --git a/ft_isprint.c b/ft_isprint.c
index 6c9faed..c04cf4f 100644
--- a/ft_isprint.c
+++ b/ft_isprint.c
@@ -6,10 +6,12 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/04 21:25:31 by dkaiser #+# #+# */
-/* Updated: 2024/03/04 21:27:57 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:11:14 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "libft.h"
+
int ft_isprint(int c)
{
if (c >= ' ' && c <= '~')
diff --git a/ft_memchr.c b/ft_memchr.c
index da3b0a6..568faa6 100644
--- a/ft_memchr.c
+++ b/ft_memchr.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 15:23:01 by dkaiser #+# #+# */
-/* Updated: 2024/03/06 15:50:06 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:16:25 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <string.h>
+#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
diff --git a/ft_memcmp.c b/ft_memcmp.c
index a1e18da..0bd52df 100644
--- a/ft_memcmp.c
+++ b/ft_memcmp.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 15:54:13 by dkaiser #+# #+# */
-/* Updated: 2024/03/06 19:45:09 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:13:54 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <string.h>
+#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
diff --git a/ft_memcpy.c b/ft_memcpy.c
index 0ca79fa..768d500 100644
--- a/ft_memcpy.c
+++ b/ft_memcpy.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 11:15:12 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 13:48:53 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:14:24 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <string.h>
+#include "libft.h"
void *ft_memcpy(void *dst, const void *src, size_t n)
{
diff --git a/ft_memmove.c b/ft_memmove.c
index e4aa03e..5d12f20 100644
--- a/ft_memmove.c
+++ b/ft_memmove.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 11:41:44 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 13:50:41 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:14:38 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <string.h>
+#include "libft.h"
void *ft_memmove(void *dst, const void *src, size_t len)
{
diff --git a/ft_memset.c b/ft_memset.c
index 60a18e9..58c5e1e 100644
--- a/ft_memset.c
+++ b/ft_memset.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 09:58:19 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 11:42:44 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:13:09 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <string.h>
+#include "libft.h"
void *ft_memset(void *b, int c, size_t len)
{
diff --git a/ft_putchar_fd.c b/ft_putchar_fd.c
index 5a1808d..5334e0e 100644
--- a/ft_putchar_fd.c
+++ b/ft_putchar_fd.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 20:36:14 by dkaiser #+# #+# */
-/* Updated: 2024/03/06 21:18:50 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:19:59 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <unistd.h>
+#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
diff --git a/ft_putendl_fd.c b/ft_putendl_fd.c
index 9929875..ab08ec4 100644
--- a/ft_putendl_fd.c
+++ b/ft_putendl_fd.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 20:47:17 by dkaiser #+# #+# */
-/* Updated: 2024/03/06 20:49:12 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:20:39 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <unistd.h>
+#include "libft.h"
void ft_putendl_fd(char *s, int fd)
{
diff --git a/ft_putstr_fd.c b/ft_putstr_fd.c
index 3be5a70..4dd472b 100644
--- a/ft_putstr_fd.c
+++ b/ft_putstr_fd.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 20:43:05 by dkaiser #+# #+# */
-/* Updated: 2024/03/06 20:45:40 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:20:16 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <unistd.h>
+#include "libft.h"
void ft_putstr_fd(char *s, int fd)
{
diff --git a/ft_strchr.c b/ft_strchr.c
index 0b20bb4..ecf522e 100644
--- a/ft_strchr.c
+++ b/ft_strchr.c
@@ -6,10 +6,12 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 14:12:39 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 16:10:27 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:15:56 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "libft.h"
+
char *ft_strchr(const char *s, int c)
{
int i;
@@ -21,15 +23,18 @@ char *ft_strchr(const char *s, int c)
return ((char *)&s[i]);
i++;
}
- if (!c)
+ if (!(char)c)
return ((char *)&s[i]);
return (0);
}
/* #include <stdio.h> */
/* #include <string.h> */
-/* int main() { */
-/* char str[] = "Hello world"; */
-/* printf("strchr: %s\n", strchr(str, 'o')); */
-/* printf("ft_strchr: %s\n", ft_strchr(str, 'o')); */
+
+/* int main(void) */
+/* { */
+/* char str[] = "teste"; */
+
+/* printf("strchr: %p\n", strchr(str, '\0')); */
+/* printf("ft_strchr: %p\n", ft_strchr(str, '\0')); */
/* } */
diff --git a/ft_strdup.c b/ft_strdup.c
index af7ab12..1282c36 100644
--- a/ft_strdup.c
+++ b/ft_strdup.c
@@ -6,33 +6,38 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 19:54:16 by dkaiser #+# #+# */
-/* Updated: 2024/03/06 20:24:51 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:17:47 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <stdlib.h>
+#include "libft.h"
char *ft_strdup(const char *s1)
{
char *result;
int len;
+ int i;
len = 0;
- while (*(s1++))
+ while (s1[len])
len++;
result = malloc(len + 1);
if (!result)
return (0);
- result[++len] = '\0';
- while (len--)
- result[len] = *(--s1);
+ result[len] = '\0';
+ i = 0;
+ while (i < len)
+ {
+ result[i] = s1[i];
+ i++;
+ }
return (result);
}
/* #include <stdio.h> */
/* int main() { */
/* char *output; */
-/* char input[] = "Dies ist ein Test."; */
+/* char input[] = "test"; */
/* output = ft_strdup(input); */
/* printf("%s\n", output); */
/* } */
diff --git a/ft_strjoin.c b/ft_strjoin.c
index c399c87..ebcd611 100644
--- a/ft_strjoin.c
+++ b/ft_strjoin.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 10:15:33 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 14:11:30 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:18:27 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <stdlib.h>
+#include "libft.h"
static int get_len(char const *s)
{
diff --git a/ft_strlcat.c b/ft_strlcat.c
index 0ce0e19..d49dfad 100644
--- a/ft_strlcat.c
+++ b/ft_strlcat.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 13:36:59 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 16:09:50 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:15:10 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <string.h>
+#include "libft.h"
/* size_t ft_strlcat(char *dst, const char *src, size_t dstsize) */
/* { */
diff --git a/ft_strlcpy.c b/ft_strlcpy.c
index b4f6abc..1cc62e5 100644
--- a/ft_strlcpy.c
+++ b/ft_strlcpy.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 12:45:25 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 14:01:05 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:14:56 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <string.h>
+#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
{
diff --git a/ft_strlen.c b/ft_strlen.c
index e201765..867c5eb 100644
--- a/ft_strlen.c
+++ b/ft_strlen.c
@@ -6,10 +6,12 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/04 21:29:35 by dkaiser #+# #+# */
-/* Updated: 2024/03/04 21:31:24 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:11:48 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "libft.h"
+
int ft_strlen(const char *str)
{
int len;
diff --git a/ft_strncmp.c b/ft_strncmp.c
index af24b2a..9d30ee7 100644
--- a/ft_strncmp.c
+++ b/ft_strncmp.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 14:45:10 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 14:26:15 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:16:10 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <string.h>
+#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
diff --git a/ft_strnstr.c b/ft_strnstr.c
index 2b96b64..54868d4 100644
--- a/ft_strnstr.c
+++ b/ft_strnstr.c
@@ -6,21 +6,23 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 16:07:54 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 16:40:20 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:16:58 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <string.h>
+#include "libft.h"
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
size_t i;
size_t k;
+ if (len < 0 || (!haystack[0] && needle[0]))
+ return (0);
i = 0;
if (*needle == '\0' || needle == haystack)
return ((char *)haystack);
- while (i < len)
+ while (i < len && haystack[i])
{
k = 0;
while (haystack[i + k] && haystack[i + k] == needle[k] && i + k < len)
@@ -38,9 +40,10 @@ char *ft_strnstr(const char *haystack, const char *needle, size_t len)
/* int main(void) */
/* { */
-/* char haystack[] = "M"; */
-/* char needle[] = "MZIRIBMZE"; */
+/* char haystack[] = "abc"; */
+/* char needle[] = "abcde"; */
+/* size_t len = 5; */
-/* printf("strnstr: %s\n", strnstr(haystack, haystack, 2)); */
-/* printf("ft_strnstr: %s\n", ft_strnstr(haystack, haystack, 2)); */
+/* printf("strnstr: %s\n", strnstr(haystack, needle, len)); */
+/* printf("ft_strnstr: %s\n", ft_strnstr(haystack, needle, len)); */
/* } */
diff --git a/ft_strrchr.c b/ft_strrchr.c
index ac0d0ab..5d31654 100644
--- a/ft_strrchr.c
+++ b/ft_strrchr.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 14:25:30 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 14:09:13 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 12:51:38 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,7 +23,7 @@ char *ft_strrchr(const char *s, int c)
last_occurrence = (char *)&s[i];
i++;
}
- if (!c)
+ if (!(char)c)
last_occurrence = (char *)&s[i];
return (last_occurrence);
}
diff --git a/ft_strtrim.c b/ft_strtrim.c
index 933987b..ff4056e 100644
--- a/ft_strtrim.c
+++ b/ft_strtrim.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/07 10:24:17 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 14:47:40 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:18:40 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <stdlib.h>
+#include "libft.h"
static int is_in(char c, const char *str)
{
diff --git a/ft_substr.c b/ft_substr.c
index f5ee2aa..bf65c8d 100644
--- a/ft_substr.c
+++ b/ft_substr.c
@@ -6,11 +6,11 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 21:58:31 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 14:55:55 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:18:11 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#include <stdlib.h>
+#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
@@ -20,20 +20,19 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
i = 0;
while (s[i])
i++;
+ if (start >= i)
+ len = 0;
if (i - start < len)
len = (i - start);
- if (start >= len)
- len = 0;
result = malloc(len + 1);
- if (result)
+ if (!result)
+ return (0);
+ result[len] = '\0';
+ i = 0;
+ while (i < len)
{
- result[len] = '\0';
- i = 0;
- while (i < len)
- {
- result[i] = s[i + start];
- i++;
- }
+ result[i] = s[i + start];
+ i++;
}
return (result);
}
@@ -42,6 +41,6 @@ char *ft_substr(char const *s, unsigned int start, size_t len)
/* int main () */
/* { */
/* char s[] = "Hello there"; */
-/* char *substr = ft_substr(s, 25, 10); */
+/* char *substr = ft_substr(s, 0, 2); */
/* printf("%s\n", substr); */
/* } */
diff --git a/ft_tolower.c b/ft_tolower.c
index 31e848f..c81b9ef 100644
--- a/ft_tolower.c
+++ b/ft_tolower.c
@@ -6,10 +6,12 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/04 21:49:28 by dkaiser #+# #+# */
-/* Updated: 2024/03/06 11:49:49 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:15:39 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "libft.h"
+
int ft_tolower(int c)
{
if (c >= 'A' && c <= 'Z')
diff --git a/ft_toupper.c b/ft_toupper.c
index 5082232..51e4ba6 100644
--- a/ft_toupper.c
+++ b/ft_toupper.c
@@ -6,10 +6,12 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/04 21:33:34 by dkaiser #+# #+# */
-/* Updated: 2024/03/04 21:49:16 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:15:26 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "libft.h"
+
int ft_toupper(int c)
{
if (c >= 'a' && c <= 'z')
diff --git a/libft.h b/libft.h
index 8fa6fd4..e646b9e 100644
--- a/libft.h
+++ b/libft.h
@@ -6,12 +6,16 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/06 21:38:24 by dkaiser #+# #+# */
-/* Updated: 2024/03/07 16:23:00 by dkaiser ### ########.fr */
+/* Updated: 2024/03/10 13:26:25 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
-#ifndef LIBFT_H_
-# define LIBFT_H_
+#ifndef LIBFT_H
+# define LIBFT_H
+
+# include <stdlib.h>
+# include <string.h>
+# include <unistd.h>
int ft_isalpha(int c);
int ft_isdigit(int c);