-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
30 lines (27 loc) · 1.21 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: nopereir <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/20 09:17:12 by nopereir #+# #+# */
/* Updated: 2022/06/20 22:32:33 by nopereir ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *res;
if (!s)
return (0);
if (ft_strlen(s) < start)
len = 0;
if (ft_strlen(s + start) < len)
len = ft_strlen(s + start);
res = malloc(sizeof(char) * (len + 1));
if (!res)
return (0);
ft_strlcpy(res, s + start, len + 1);
return (res);
}