-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
34 lines (31 loc) · 1.31 KB
/
ft_substr.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_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gaaraujo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/08 17:47:12 by gaaraujo #+# #+# */
/* Updated: 2024/12/08 19:18:34 by gaaraujo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *str;
size_t str_length;
if (ft_strlen(s) <= start || len == 0)
str = ft_strdup("");
else
{
str_length = ft_strlen(s) - start;
if (str_length > len)
str_length = len;
str = (char *) malloc(sizeof(char) * str_length + 1);
if (str == NULL)
return (NULL);
ft_memcpy(str, &s[start], str_length);
str[str_length] = '\0';
}
return (str);
}