-
Notifications
You must be signed in to change notification settings - Fork 2
/
ft_substr.c
36 lines (33 loc) · 1.27 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: marsoare <marsoare@student.42porto.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/13 13:14:58 by marsoare #+# #+# */
/* Updated: 2024/04/19 17:28:41 by marsoare ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *c, unsigned int start, size_t len)
{
char *subs;
size_t i;
if (start > ft_strlen(c))
return (ft_strdup(""));
if (len > ft_strlen(c) - start)
len = ft_strlen(c) - start;
subs = (char *)malloc(sizeof(char) * len + 1);
if (subs == 0)
return (NULL);
i = 0;
while (i < len)
{
subs[i] = c[start];
start++;
i++;
}
subs[i] = 0;
return (subs);
}