-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
29 lines (26 loc) · 1.17 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttavares <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/10 17:57:27 by ttavares #+# #+# */
/* Updated: 2022/11/21 16:42:43 by ttavares ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *ptr;
ptr = malloc(sizeof(char) *(len + 1));
if (!ptr || !s)
return (0);
if (start >= ft_strlen(s))
{
ft_memset(ptr, '\0', len + 1);
return (ptr);
}
ft_strlcpy(ptr, s + start, len + 1);
return (ptr);
}