-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
37 lines (34 loc) · 1.31 KB
/
ft_substr.c
File metadata and controls
37 lines (34 loc) · 1.31 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: uviana-a <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/21 14:08:25 by uviana-a #+# #+# */
/* Updated: 2023/04/21 14:08:26 by uviana-a ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
void *ptr_substr;
size_t i;
if (ft_strlen(s) - start < len)
len = ft_strlen(s) - start;
if (ft_strlen(s) < start)
len = 0;
ptr_substr = malloc (sizeof(char) * (len + 1));
if (!ptr_substr)
{
return (NULL);
}
i = 0;
while (i < len)
{
((char *)ptr_substr)[i] = s[start + i];
i++;
}
((char *)ptr_substr)[i] = '\0';
return ((char *)ptr_substr);
}