-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr.c
39 lines (36 loc) · 1.34 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
39
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_substr.c :+: :+: */
/* +:+ */
/* By: splattje <splattje@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2023/10/23 17:27:32 by splattje #+# #+# */
/* Updated: 2023/10/25 10:04:13 by splattje ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t count;
size_t size;
char *tab;
if (!s)
return (NULL);
if ((unsigned int)ft_strlen(s) < start)
return (ft_strdup(""));
size = ft_strlen(s + start);
if (size < len)
len = size;
tab = (char *)malloc((len + 1) * sizeof(char));
if (tab == NULL)
return (NULL);
count = 0;
while (count < len)
{
tab[count] = s[start + count];
count++;
}
tab[count] = '\0';
return (tab);
}