-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
41 lines (38 loc) · 1.27 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
37
38
39
40
41
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_substr.c :+: :+: */
/* +:+ */
/* By: kgajadie <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/11/22 11:10:49 by kgajadie #+# #+# */
/* Updated: 2020/11/24 11:47:11 by kgajadie ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *res;
unsigned int end;
int i;
if (!s)
return (NULL);
end = start + len;
res = malloc(len + 1);
i = 0;
if (res == NULL)
return (NULL);
if (start >= ft_strlen(s))
{
ft_bzero(res, 1);
return (res);
}
while (start < end)
{
res[i] = s[start];
start++;
i++;
}
res[i] = '\0';
return (res);
}