-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strsub.c
40 lines (37 loc) · 1.25 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: dnichol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/07 17:07:40 by dnichol #+# #+# */
/* Updated: 2019/09/11 18:50:40 by dnichol ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
char *dest;
unsigned int i;
i = 0;
if (s != NULL)
{
dest = ft_strnew(len);
if (dest != NULL)
{
while (s[start] != '\0' && i < (unsigned int)len)
{
dest[i] = s[start];
start++;
i++;
}
}
else
return (NULL);
}
else
return (NULL);
dest[i] = '\0';
return (dest);
}