-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
33 lines (30 loc) · 1.24 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
32
33
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariahi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/12 12:56:50 by ariahi #+# #+# */
/* Updated: 2021/11/27 18:22:59 by ariahi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(const char *s, unsigned int start, size_t len)
{
char *sub;
size_t s_len;
if (!s)
return (NULL);
s_len = ft_strlen(s);
if (start > s_len)
start = s_len;
if (start + len > s_len)
len = s_len - start;
sub = (char *)malloc(len + 1);
if (!sub)
return (NULL);
ft_memmove(sub, s + start, len);
sub[len] = '\0';
return (sub);
}