summaryrefslogtreecommitdiff
path: root/ft_strdup.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-03-10 13:37:45 +0100
committerDominik Kaiser2024-03-10 13:37:45 +0100
commit4e19b82398e0cfaa3ca0b9f68772c88d103ff6ea (patch)
treee25f459959a69578322529aca6d2a02cb2d3dfcf /ft_strdup.c
parent3c90d29fe5bf9ba6da090cd59c8c139d269f8bd4 (diff)
downloadlibft-4e19b82398e0cfaa3ca0b9f68772c88d103ff6ea.tar.gz
libft-4e19b82398e0cfaa3ca0b9f68772c88d103ff6ea.zip
Complete missing functions and add header
Diffstat (limited to 'ft_strdup.c')
-rw-r--r--ft_strdup.c19
1 files changed, 12 insertions, 7 deletions
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); */
/* } */