-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
35 lines (32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dlago-mo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/04 15:41:17 by dlago-mo #+# #+# */
/* Updated: 2021/02/08 11:41:03 by dlago-mo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *s2;
unsigned int i;
i = 0;
if (!s)
return (NULL);
if (ft_strlen(s) < start)
len = 0;
s2 = malloc(sizeof(char) * (len + 1));
if (s2 == NULL)
return (NULL);
while (s[i] && i < len)
{
s2[i] = s[start + i];
i++;
}
s2[i] = '\0';
return (s2);
}