-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
30 lines (27 loc) · 1.22 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ogenc <ogenc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/15 18:16:13 by ogenc #+# #+# */
/* Updated: 2022/12/28 07:48:28 by ogenc ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(const char *s, unsigned int start, size_t len)
{
char *str;
if (!s)
return (0);
if (start > ft_strlen(s))
return (ft_strdup(""));
if (len > ft_strlen(s + start))
len = ft_strlen(s + start);
str = malloc(sizeof(char) * (len + 1));
if (!str)
return (0);
ft_strlcpy(str, s + start, len + 1);
return (str);
}