-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strsub.c
34 lines (31 loc) · 1.19 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mesafi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/05 22:56:17 by mesafi #+# #+# */
/* Updated: 2020/01/20 13:31:52 by mesafi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
#include <string.h>
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
char *p;
int i;
if (!s)
return (NULL);
i = 0;
p = (char *)malloc((len + 1) * sizeof(char));
if (!p)
return (NULL);
while (len--)
{
p[i++] = s[start++];
}
p[i] = '\0';
return (p);
}