-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
39 lines (36 loc) · 1.31 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mriant <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/02 14:25:42 by mriant #+# #+# */
/* Updated: 2021/12/08 10:34:25 by mriant ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *result;
size_t i;
if (!s || start > ft_strlen(s))
{
result = ft_calloc(1, 1);
return (result);
}
if (ft_strlen(s) - start < len)
i = ft_strlen(s) - start;
else
i = len;
result = ft_calloc(sizeof(char), (i + 1));
if (!result)
return (NULL);
i = 0;
while (s[i + start] && i < len)
{
result[i] = s[i + start];
i ++;
}
return (result);
}