-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
38 lines (35 loc) · 1.3 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: selhilal <selhilal@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/19 09:17:03 by selhilal #+# #+# */
/* Updated: 2022/10/27 18:17:10 by selhilal ### ########.fr */
/* */
/* ************************************************************************** */
#include"libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *ptr;
size_t i;
if (!s)
return (NULL);
if (start < ft_strlen(s))
{
if ((ft_strlen(s) - start) < len)
ptr = malloc(ft_strlen(s) - start + 1);
else
ptr = malloc(len + 1);
if (!ptr)
return (NULL);
i = -1;
while (++i < len && s[start])
ptr[i] = s[start++];
ptr[i] = 0;
return (ptr);
}
ptr = ft_strdup("");
return (ptr);
}