-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
31 lines (28 loc) · 1.23 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: aahlyel <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/10 18:03:02 by aahlyel #+# #+# */
/* Updated: 2022/10/26 16:06:58 by aahlyel ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(const char *s, unsigned int start, size_t len)
{
char *dest;
size_t s_len;
if (!s)
return (NULL);
if (start >= ft_strlen(s))
return (ft_strdup(""));
s_len = ft_strlen(s + start);
if (len > s_len)
len = s_len;
dest = ft_calloc(len + 1, sizeof(char));
if (dest)
ft_memcpy(dest, (s + start), len);
return (dest);
}