-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
30 lines (27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dbrandao <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/08 18:12:54 by dbrandao #+# #+# */
/* Updated: 2022/07/01 21:07:39 by dbrandao ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t start_size;
char *substr;
if (!s || ft_strlen(s) < start + 1)
return (ft_strdup(""));
start_size = ft_strlen(&s[start]);
if (start_size < len)
len = start_size;
substr = ((char *) malloc(len + 1));
if (!substr)
return (NULL);
ft_strlcpy(substr, &s[start], len + 1);
return (substr);
}