-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
36 lines (33 loc) · 1.26 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
34
35
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abouramd <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 17:59:16 by abouramd #+# #+# */
/* Updated: 2022/10/24 12:49:05 by abouramd ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *p;
size_t index;
size_t n;
n = 0;
if (!s)
return (NULL);
if (start <= ft_strlen(s))
n = ft_strlen(s) - start;
else
return (ft_strdup(""));
if (len < n)
n = len;
index = 0;
p = (char *)malloc((1 + n) * sizeof(char));
if (!p)
return (NULL);
ft_strlcpy(p, s + start, n + 1);
return (p);
}