-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
38 lines (35 loc) · 1.25 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
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vsimeono <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/11 19:45:05 by vsimeono #+# #+# */
/* Updated: 2021/09/29 18:02:03 by vsimeono ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *p;
size_t i;
size_t lenstr;
i = 0;
if (!s)
return (NULL);
p = (char *)malloc((len + 1) * sizeof(char));
if (!p)
return (NULL);
lenstr = ft_strlen(s);
if (start >= lenstr)
return (p);
while (i < len)
{
*(p + i) = *(s + start);
i++;
start++;
}
*(p + i) = '\0';
return (p);
}