-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
39 lines (36 loc) · 1.24 KB
/
ft_substr.c
File metadata and controls
39 lines (36 loc) · 1.24 KB
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: mbari <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/19 18:29:06 by mbari #+# #+# */
/* Updated: 2019/11/18 16:49:56 by mbari ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
size_t size;
char *s2;
if (s == NULL)
return (NULL);
s2 = (char *)malloc(sizeof(char) * len + 1);
size = ft_strlen(s);
if (!s2)
return (NULL);
i = 0;
if (start < size)
{
while (i < len)
{
s2[i] = s[start];
start++;
i++;
}
}
s2[i] = '\0';
return (s2);
}