-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
28 lines (25 loc) · 1.19 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vscabell <vscabell@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/22 17:31:58 by vscabell #+# #+# */
/* Updated: 2020/06/09 18:29:47 by vscabell ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *substr;
if (!s)
return (NULL);
if (start > ft_strlen(s))
return (ft_strdup(""));
if (!(substr = malloc((len + 1) * sizeof(char))))
return (NULL);
ft_memcpy(substr, &s[start], len);
substr[len] = '\0';
return (substr);
}