-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
38 lines (35 loc) · 1.32 KB
/
ft_substr.c
File metadata and controls
38 lines (35 loc) · 1.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ymassiou <ymassiou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 12:45:21 by ymassiou #+# #+# */
/* Updated: 2023/11/16 15:37:25 by ymassiou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(const char *s, unsigned int start, size_t len)
{
size_t i;
char *result;
if (s == NULL)
return (NULL);
if (start > ft_strlen(s))
return ((char *)ft_calloc(1, 1));
if (len > ft_strlen(&s[start]))
len = ft_strlen(&s[start]);
i = 0;
result = NULL;
result = (char *)malloc(len + 1);
if (result == NULL)
return (NULL);
while (i < len)
{
result[i] = s[start + i];
i++;
}
result[len] = 0;
return (result);
}