-
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.27 KB
/
Copy pathft_substr.c
File metadata and controls
32 lines (29 loc) · 1.27 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: rahidalg <rahidalg@student.42madrid> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/18 15:14:25 by rahidalg #+# #+# */
/* Updated: 2024/04/18 11:16:27 by rahidalg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *out;
if (!s)
return ((void *)0);
if (start >= ft_strlen(s))
start = ft_strlen(s);
if (ft_strlen(s) < start)
len = 0;
if (ft_strlen(s + start) < len)
len = ft_strlen(s + start);
out = malloc(sizeof(char) * (len + 1));
if (!out)
return ((void *)0);
ft_strlcpy(out, s + start, len + 1);
return (out);
}