-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
36 lines (33 loc) · 1.37 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
35
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ldel-val <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/26 14:52:49 by ldel-val #+# #+# */
/* Updated: 2024/10/10 19:09:25 by ldel-val ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *substr;
if (!s)
return (NULL);
if (start >= ft_strlen(s))
return (ft_calloc(1, sizeof(char)));
if (len > ft_strlen(s + start))
len = ft_strlen(s + start);
substr = (char *)malloc(sizeof(char) * len + 1);
if (!substr)
return (NULL);
ft_strlcpy(substr, ((char *)s) + start, len + 1);
return (substr);
}
/*
int main(void)
{
char s[] = "Hola Hola mundo mundo";
printf("%s", ft_substr(s, 5, 10));
}*/