-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
36 lines (33 loc) · 1.22 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
33
34
35
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jamrabhi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/18 22:29:35 by jamrabhi #+# #+# */
/* Updated: 2021/06/05 20:01:33 by jamrabhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
char *rt;
i = 0;
if (!s)
return (NULL);
if (start > ft_strlen(s))
len = 0;
rt = (char *)malloc(sizeof(*rt) * (len + 1));
if (!rt)
return (NULL);
while (*s + start && i < len)
{
rt[i] = s[start];
i++;
start++;
}
rt[i] = '\0';
return (rt);
}