-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
39 lines (36 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_substr.c :+: :+: */
/* +:+ */
/* By: greed <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/11/01 09:07:10 by greed #+# #+# */
/* Updated: 2019/11/06 14:44:09 by greed ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
char *dst;
unsigned int tmp;
i = 0;
if (!(s))
return (NULL);
tmp = ft_strlen(s);
if (start > tmp)
return (ft_strdup(""));
dst = (char*)malloc(len + 1);
if (!(dst))
return (NULL);
while (i < len)
{
dst[i] = s[start];
start++;
i++;
}
dst[i] = '\0';
return (dst);
}