-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
33 lines (30 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elraira- <elraira-@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/17 16:58:51 by elraira- #+# #+# */
/* Updated: 2021/08/19 11:01:41 by elraira- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *str;
size_t str_len;
if (!s)
return (0);
str_len = ft_strlen((char *)s);
if (start > str_len)
return (ft_strdup(""));
if (str_len - start >= len)
str = (char *)malloc((len + 1) * sizeof(char));
else
str = (char *)malloc((str_len - start + 1) * sizeof(char));
if (!str)
return (0);
ft_strlcpy(str, (s + start), (len + 1));
return (str);
}