-
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.25 KB
/
ft_substr.c
File metadata and controls
32 lines (29 loc) · 1.25 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: aymohamm <aymohamm@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 14:51:47 by aymohamm #+# #+# */
/* Updated: 2023/11/22 12:09:06 by aymohamm ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *new;
size_t slen;
if (!s)
return (NULL);
slen = ft_strlen(s);
if (start > slen)
return (ft_strdup(""));
if (len > slen - start)
len = slen - start;
new = (char *)malloc((len + 1) * sizeof(char));
if (!new)
return (NULL);
ft_strlcpy(new, s + start, len + 1);
return (new);
}