-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
42 lines (39 loc) · 1.38 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
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rblondia <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/03 15:01:39 by rblondia #+# #+# */
/* Updated: 2021/11/08 17:56:30 by rblondia ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *new;
int index;
if (!s)
return (NULL);
if (start > ft_strlen(s))
{
new = malloc(sizeof(char));
new[0] = '\0';
return (new);
}
index = 0;
while (s[start + index] && index < (int) len)
index++;
new = malloc((index + 1) * sizeof(char));
if (!new)
return (NULL);
index = 0;
while (s[start + index] && index < (int) len)
{
new[index] = s[start + index];
index++;
}
new[index] = '\0';
return (new);
}