-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
32 lines (29 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yde-goes <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/11 14:38:47 by yde-goes #+# #+# */
/* Updated: 2022/06/28 15:22:07 by yde-goes ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t s_len;
char *substr;
if (!s)
return (NULL);
s_len = ft_strlen(s);
if (start >= s_len)
return (ft_strdup(""));
if (start + len > s_len)
len = s_len - start;
substr = malloc((len + 1) * sizeof(*substr));
if (substr == NULL)
return (NULL);
ft_strlcpy(substr, s + start, len + 1);
return (substr);
}