-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
31 lines (28 loc) · 1.25 KB
/
ft_substr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lenzo-pe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/13 04:44:21 by lenzo-pe #+# #+# */
/* Updated: 2021/04/25 23:38:19 by lenzo-pe ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_string.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *ptr;
size_t maxlen;
if (!s)
return (NULL);
if (start >= ft_strlen(s))
return (ft_strdup(""));
maxlen = ft_strnlen(s, len);
ptr = (char *)malloc(sizeof(char) * (maxlen + 1));
if (!ptr)
return (NULL);
ft_memcpy(ptr, (s + start), maxlen);
ptr[maxlen] = '\0';
return (ptr);
}