-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
34 lines (31 loc) · 1.28 KB
/
ft_substr.c
File metadata and controls
34 lines (31 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sel-abbo <sel-abbo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/28 14:29:10 by sel-abbo #+# #+# */
/* Updated: 2024/11/04 23:01:40 by sel-abbo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *res;
size_t i;
size_t len_a;
i = 0;
if (!s || start >= (unsigned int)ft_strlen(s))
return (ft_calloc(1, 1));
len_a = ft_strlen(s) - start;
if (len > len_a)
len = len_a;
res = (char *)malloc(len + 1);
if (!res)
return (NULL);
while (s[start] && i < len)
res[i++] = s[start++];
res[i] = '\0';
return (res);
}