-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strsub.c
36 lines (33 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dlenskyi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/28 21:06:11 by dlenskyi #+# #+# */
/* Updated: 2018/10/28 21:06:12 by dlenskyi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
size_t i;
char *sstr;
char *str;
if (!s)
return (NULL);
i = 0;
str = (char *)s;
sstr = (char*)ft_memalloc(sizeof(char) * (len + 1));
if (!sstr)
return (NULL);
while (str[i] && i < len)
{
sstr[i] = str[start];
start++;
i++;
}
sstr[i] = '\0';
return (sstr);
}