-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strsub.c
36 lines (33 loc) · 1.27 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: hshawand <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/03 12:36:19 by hshawand #+# #+# */
/* Updated: 2019/04/15 12:21:28 by hshawand ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <string.h>
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
char *substring;
size_t max;
size_t i;
if (!s || len + 1 == 0)
return (0);
substring = (char *)malloc(sizeof(char) * (len + 1));
if (!substring)
return (NULL);
max = len;
i = 0;
while (i < max)
{
substring[i] = s[start + i];
i++;
}
substring[i] = '\0';
return (substring);
}