-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_substr.c
32 lines (29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dpoveda- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/17 17:48:02 by dpoveda- #+# #+# */
/* Updated: 2023/03/13 17:29:15 by dpoveda- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/ft_str.h"
char *ft_substr(const char *s, unsigned int start, size_t len)
{
size_t out_len;
char *out;
if (!s)
return (NULL);
if (ft_strlen(s) < start)
return (ft_strdup(""));
out_len = ft_strlen(s + start);
if (out_len < len)
len = out_len;
out = malloc(len + 1);
if (!out)
return (NULL);
ft_strlcpy(out, s + start, len + 1);
return (out);
}