-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strsub.c
executable file
·38 lines (35 loc) · 1.31 KB
/
ft_strsub.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_strsub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: luperez <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/15 19:23:34 by luperez #+# #+# */
/* Updated: 2014/11/19 07:35:32 by luperez ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
int i;
char *move;
char *sub;
if (start == '\0' && len == 0)
return (ft_strnew(1));
if (s == NULL || start < 1 || len < 1)
return (NULL);
i = -1;
if (len > 0)
sub = (char *)malloc(sizeof(char) * len + 1);
if (sub == NULL)
return (NULL);
move = (char *)&s[start];
while (len--)
{
i++;
sub[i] = move[i];
}
sub[++i] = '\0';
return (sub);
}