-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
30 lines (27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atabiti <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/13 14:43:40 by atabiti #+# #+# */
/* Updated: 2021/11/22 17:24:04 by atabiti ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *substr;
if (!s)
return (NULL);
if (start >= (size_t)ft_strlen(s))
return (ft_strdup(""));
if (len > ft_strlen(s + start))
len = ft_strlen(s + start);
substr = (char *) malloc (len + 1);
if (!substr)
return (NULL);
ft_strlcpy(substr, s + start, len + 1);
return (substr);
}