-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strsub.c
40 lines (37 loc) · 1.24 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
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nvienot <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/15 22:15:24 by nvienot #+# #+# */
/* Updated: 2018/11/21 19:43:56 by nvienot ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
char *s2;
size_t i;
size_t j;
i = 0;
j = 0;
s2 = (char *)s;
if (!s || !(s2 = ((char *)malloc(sizeof(char) * (len + 1)))))
return (NULL);
while (start != 0)
{
i++;
start--;
}
while (j < len)
{
s2[j] = s[i];
i++;
j++;
}
s2[j] = '\0';
return (s2);
}