-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
34 lines (31 loc) · 759 Bytes
/
ft_substr.c
File metadata and controls
34 lines (31 loc) · 759 Bytes
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
/*######## ## ## ####### ###### ########
## ## ## ## ## ## ## ##
## ## ## ## ## ## ##
###### ####### ##### ## ## ###### ######
## ## ## ## ## ## ##
## ## ## ## ## ## ## ##
######## ## ## ####### ###### ########*/
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
unsigned int i;
char *p;
if (start > ft_strlen(s))
{
return (ft_strdup(""));
}
if (ft_strlen(s) < len)
len = ft_strlen(s);
i = 0;
p = malloc((sizeof(char)) * (len + 1));
if (p == NULL)
return (NULL);
while (s[start] && i < len)
{
p[i] = s[start];
i++;
start++;
}
p[i] = '\0';
return (p);
}