-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
34 lines (31 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edboutil <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/14 13:45:18 by edboutil #+# #+# */
/* Updated: 2022/11/25 13:09:50 by edboutil ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *tab;
unsigned int i;
unsigned int len_s;
len_s = ft_strlen(s);
if (start > len_s)
len = 0;
else if (len > len_s - start)
len = len_s - start;
tab = malloc(sizeof(char) * (len + 1));
if (!tab)
return (NULL);
i = 0;
while (i < len)
tab[i++] = s[start++];
tab[i] = '\0';
return (tab);
}