-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
38 lines (35 loc) · 1.25 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: cbernot <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/09 12:30:56 by cbernot #+# #+# */
/* Updated: 2022/12/17 14:12:13 by cbernot ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *res;
size_t i;
size_t j;
if (!s)
return (0);
if (len > ft_strlen(s))
len = ft_strlen(s);
res = malloc(sizeof(char) * (len + 1));
if (!res || !s)
return (0);
i = start;
j = 0;
while (i < ft_strlen(s) && j < len)
{
res[j] = s[i];
i++;
j++;
}
res[j] = '\0';
return (res);
}