aboutsummaryrefslogtreecommitdiff
path: root/ft_substr.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-11-20 04:04:55 +0100
committerCharles <sircharlesaze@gmail.com>2019-11-20 04:04:55 +0100
commit9901cd05849fa0ef396f09f57b07807ebd96ca32 (patch)
treef2dd9c191512bfc11c994e578291cccf270de787 /ft_substr.c
parenta983b06df18647cf63fadad5b36f472e06f1075f (diff)
downloadlibft-9901cd05849fa0ef396f09f57b07807ebd96ca32.tar.gz
libft-9901cd05849fa0ef396f09f57b07807ebd96ca32.tar.bz2
libft-9901cd05849fa0ef396f09f57b07807ebd96ca32.zip
refactored everything
Diffstat (limited to 'ft_substr.c')
-rw-r--r--ft_substr.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/ft_substr.c b/ft_substr.c
index 88f7203..84d6c58 100644
--- a/ft_substr.c
+++ b/ft_substr.c
@@ -6,31 +6,21 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/17 08:28:49 by cacharle #+# #+# */
-/* Updated: 2019/10/18 11:55:44 by cacharle ### ########.fr */
+/* Updated: 2019/11/20 03:57:58 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-#include <stdlib.h>
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
- unsigned int i;
char *sub;
if (s == NULL)
return (NULL);
- if ((sub = (char*)malloc(sizeof(char) * (len + 1))) == NULL)
+ if ((sub = ft_strnew(len)) == NULL)
return (NULL);
- i = 0;
- if (!(start > ft_strlen(s)))
- {
- while (i < len && s[start + i])
- {
- sub[i] = s[start + i];
- i++;
- }
- }
- sub[i] = '\0';
- return (sub);
+ if (start > ft_strlen(s))
+ return (sub);
+ return (ft_strncpy(sub, s + start, len));
}