-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
33 lines (30 loc) · 1.28 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: juchoi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/21 16:06:36 by juchoi #+# #+# */
/* Updated: 2021/02/08 23:09:15 by juchoi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *str;
unsigned int s_len;
size_t n_len;
if (!s)
return (0);
s_len = ft_strlen(s);
if (s_len < start)
return (ft_strdup(""));
n_len = ft_strlen(s + start);
if (n_len < len)
len = n_len;
if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
return (0);
ft_strlcpy(str, s + start, len + 1);
return (str);
}