-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
40 lines (37 loc) · 1.35 KB
/
ft_substr.c
File metadata and controls
40 lines (37 loc) · 1.35 KB
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
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edforte <edforte@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/15 19:22:34 by edforte #+# #+# */
/* Updated: 2024/01/24 20:56:33 by edforte ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *strres;
unsigned int end;
int i;
if (!s)
return (NULL);
if (start >= ft_strlen(s))
return (ft_strdup(""));
if (len >= (ft_strlen(s)))
len = (ft_strlen(s));
end = start + len;
strres = (char *) malloc((len + 1) * sizeof(char));
if (!strres)
return (NULL);
i = 0;
while (start < end)
{
strres[i] = s[start];
start ++;
i ++;
}
strres[i] = '\0';
return (strres);
}