-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
32 lines (29 loc) · 1.28 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: msubtil- <msubtil-@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/12 15:31:45 by msubtil- #+# #+# */
/* Updated: 2022/05/11 23:30:25 by msubtil- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *tmp;
size_t slen;
if (s == NULLPTR)
return (NULLPTR);
slen = ft_strlen(s);
if (start >= slen)
return (ft_strdup(""));
else if (len > (slen - start))
len = slen - start;
tmp = (char *) malloc(sizeof(char) * (len + 1));
if (tmp == NULLPTR)
return (NULLPTR);
ft_strlcpy(tmp, s + start, len + 1);
return (tmp);
}