From 3c90d29fe5bf9ba6da090cd59c8c139d269f8bd4 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Sun, 10 Mar 2024 13:35:18 +0100 Subject: Add everything --- ft_substr.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ft_substr.c (limited to 'ft_substr.c') diff --git a/ft_substr.c b/ft_substr.c new file mode 100644 index 0000000..f5ee2aa --- /dev/null +++ b/ft_substr.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + size_t i; + char *result; + + i = 0; + while (s[i]) + i++; + if (i - start < len) + len = (i - start); + if (start >= len) + len = 0; + result = malloc(len + 1); + if (result) + { + result[len] = '\0'; + i = 0; + while (i < len) + { + result[i] = s[i + start]; + i++; + } + } + return (result); +} + +/* #include */ +/* int main () */ +/* { */ +/* char s[] = "Hello there"; */ +/* char *substr = ft_substr(s, 25, 10); */ +/* printf("%s\n", substr); */ +/* } */ -- cgit v1.2.3