-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
32 lines (28 loc) · 1.33 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
/* ******************************************************************************* */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sandraemiko<[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/20 20:09:04 by sandraemiko #+# #+# */
/* Updated: 2023/02/27 21:22:10 by sandraemiko ### ########.fr */
/* */
/* ******************************************************************************* */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *sub_str;
sub_str = malloc((len + 1) * sizeof(char));
if (s == NULL || sub_str == NULL)
return (NULL);
if (len > (ft_strlen(s) - start))
len = ft_strlen(s) - start;
if (len == 0 || start >= ft_strlen(s))
{
*sub_str = '\0';
return (sub_str);
}
ft_strlcpy(sub_str, s + start, len + 1);
return (sub_str);
}