-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
39 lines (36 loc) · 1.32 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
37
38
39
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adiaz-be <adiaz-be@student.42malaga.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/26 19:46:10 by adiaz-be #+# #+# */
/* Updated: 2022/09/26 19:46:29 by adiaz-be ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
unsigned int i;
char *str;
i = 0;
if (start >= ft_strlen(s))
{
str = ft_calloc(1, sizeof(char));
if (!str)
return (NULL);
return (str);
}
if (ft_strlen(s) - start < len)
len = ft_strlen(s) - start;
str = ft_calloc(sizeof(char), len + 1);
if (!str)
return (NULL);
while (s[start + i] && i < len)
{
str[i] = s[start + i];
i++;
}
return (str);
}