-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
32 lines (29 loc) · 1.28 KB
/
Copy pathft_substr.c
File metadata and controls
32 lines (29 loc) · 1.28 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ekutlay <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/20 19:17:52 by ekutlay #+# #+# */
/* Updated: 2022/01/20 21:11:49 by ekutlay ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *subs;
size_t new_len;
if (s == NULL)
return (NULL);
if ((unsigned int)ft_strlen(s) < start)
return (ft_strdup(""));
new_len = ft_strlen(s + start);
if (new_len < len)
len = new_len;
subs = (char *)malloc(sizeof(char) * (len + 1));
if (!subs)
return (NULL);
ft_strlcpy(subs, s + start, len + 1);
return (subs);
}