]> git.dkaiser.de - 42/libft.git/commitdiff
Complete missing functions and add header
authorDominik Kaiser <dkaiser@1-C-13.42heilbronn.de>
Sun, 10 Mar 2024 12:37:45 +0000 (13:37 +0100)
committerDominik Kaiser <dkaiser@1-C-13.42heilbronn.de>
Sun, 10 Mar 2024 12:37:45 +0000 (13:37 +0100)
30 files changed:
Makefile
ft_atoi.c
ft_bzero.c
ft_calloc.c
ft_isalnum.c
ft_isalpha.c
ft_isdigit.c
ft_isprint.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_putstr_fd.c
ft_strchr.c
ft_strdup.c
ft_strjoin.c
ft_strlcat.c
ft_strlcpy.c
ft_strlen.c
ft_strncmp.c
ft_strnstr.c
ft_strrchr.c
ft_strtrim.c
ft_substr.c
ft_tolower.c
ft_toupper.c
libft.h

index 3920b81cf4dd6dec493d0e1a7cb99a4c0b08c6e7..8759efa7cebe8d3ede56e0ee21345cc2106d02a0 100644 (file)
--- 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)
 
 
index 568a61605076aa35197f8a4560e0503838a2af6b..90200fb257fe2cc24ec43d326c8eec566dac3d79 100644 (file)
--- 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;
index 2f77d78d575a0c39bd78e8470b7d4db34076131a..78af51a9d8d6840440b85ad1d8132958833324fa 100644 (file)
@@ -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)
 {
index 5baf8f1773b8bd13d32bdc6524490e44c74cfaf8..2b711d957707637c6d576ff5cd78c0f1ef7c2a4a 100644 (file)
@@ -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)
 {
index 4de4a635566bc01e1db3c5fd0062c059e3f9399c..d70550098971e0647456c6e803a58883cf50cf9f 100644 (file)
@@ -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'
index 64d4b9a2072b8d4e0de49aa223a6fe07d835b832..054d96c27605a60819f2ccdec5be092a8d99be1f 100644 (file)
@@ -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'))
index 273bfa37dbebdc77bbe60b6f5bf5da2d936bdcb3..2601fee37e73ed37c98fc1a4dbebd4e0651ad4c2 100644 (file)
@@ -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')
index 6c9faed06a1dd4b272a64f318d3d494c2e65a253..c04cf4fcab7169381d1ea94686a648892d23e8b8 100644 (file)
@@ -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 <= '~')
index da3b0a650fec5c1d0b6bc9e68be785be7e6b4b0a..568faa603c66b79ae482e16bd488a631cba0a747 100644 (file)
@@ -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)
 {
index a1e18da6e4cee073a75da231cf8b7db9daf305c0..0bd52df8af2f5bc779d9fbb25c309c917da2350b 100644 (file)
@@ -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)
 {
index 0ca79fa0f231837dceb195e3df89a9dfc644544b..768d500e543407db690c0b7743aea5a575a778de 100644 (file)
@@ -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)
 {
index e4aa03ec3d0cc61a6d6f106541107b6278aca2fc..5d12f20aaee7a1317b80794e6713b2f0999a7b22 100644 (file)
@@ -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)
 {
index 60a18e9fa5909a7e5e99c5a291c989054f12eeea..58c5e1eda8faa83bb8d46843ba635c08abf49d40 100644 (file)
@@ -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)
 {
index 5a1808d0b3eae975a7c2d5a871dd8f8495612776..5334e0ead37452419f4acc270f33e78fe7fac7f2 100644 (file)
@@ -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)
 {
index 99298759dcbbc3c2499e879065ca9e95ed3ed788..ab08ec454cdece73dbc2847e632918eb046193d6 100644 (file)
@@ -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)
 {
index 3be5a705003d9cbc5f501cd5de1a4db8c8ab9b0d..4dd472b78f34505bdb0e3baae5013b2d5846c312 100644 (file)
@@ -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)
 {
index 0b20bb435fcf0e38bf3527edcad91486bf39c67b..ecf522e0d604b3618d1a5b2f79ea9280cf0d4443 100644 (file)
@@ -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')); */
 /* } */
index af7ab124a042b359a7d54b1d34cf9959e87c17e7..1282c368a3a6d6d5135d88f4e735dec3f2db2c08 100644 (file)
@@ -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); */
 /* } */
index c399c87e4e5a28e98d935fc3e85d3a4e3ae1e176..ebcd611a735eba7e9cf0400bc4c59ee38b888740 100644 (file)
@@ -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)
 {
index 0ce0e19d8695b53b5dd4ab789bb0e7a19d647f33..d49dfad8558dddf81c5a64fea7799bfac57c0bba 100644 (file)
@@ -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) */
 /* { */
index b4f6abc3cf5da80981bee81a3a2b6a513fbdd4ae..1cc62e55779eb1436cdad3f1749da8e559551603 100644 (file)
@@ -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)
 {
index e201765fdf1562d289604496b06e9ee6b27efbe4..867c5eb92ccd6641af6e7f5fcde8d3174160268b 100644 (file)
@@ -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;
index af24b2a02d489e5be5ee9cf8f12364a9498e59cd..9d30ee7db04f88f9f0da38bd7ba51db508c51487 100644 (file)
@@ -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)
 {
index 2b96b6427b8b2f9d646d924c12c2033b2b74b067..54868d43eeb7142a4a3f71fdadb934e8a268bb18 100644 (file)
@@ -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)); */
 /* } */
index ac0d0ab9044e7847d2f5bcaa472a1dbff9be69f4..5d31654a10e83bd23c41a3806517f6944be10c85 100644 (file)
@@ -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);
 }
index 933987bcef62148e47d50e805fb201e26137776f..ff4056eeb3c36c89a504992f2b6eb058a06591af 100644 (file)
@@ -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)
 {
index f5ee2aa67bbc21c53fe6a22e39a01f1df71c8447..bf65c8d41bb00286408b9fec045235aa55b165f1 100644 (file)
@@ -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); */
 /* } */
index 31e848f476b118528d6a352bae2df1be1532296c..c81b9ef864fef6c94c8b995fde2c349419dc3c80 100644 (file)
@@ -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')
index 5082232baefe726c340e45cf43e7826d5eace7ba..51e4ba6f40296cd3b53b6bffe4c874cc851680a6 100644 (file)
@@ -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 8fa6fd4dd7ba894fea21ec0b9aa1890f62f7289a..e646b9e4a59503e09f1b129b82952bb244e8a9b8 100644 (file)
--- 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);