-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
34 lines (31 loc) · 1.25 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: esuguimo <esuguimo@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/06 23:45:40 by esuguimo #+# #+# */
/* Updated: 2020/02/21 01:38:01 by esuguimo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *substring;
size_t i;
size_t length;
if (!s)
return (NULL);
i = 0;
length = ft_strlen(s);
if (!(substring = malloc((sizeof(char) * len) + 1)))
return (NULL);
while (i < len && i + start < length)
{
substring[i] = s[start + i];
i++;
}
substring[i] = '\0';
return (substring);
}