-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
53 lines (49 loc) · 1.53 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hecmarti <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/30 16:30:45 by hecmarti #+# #+# */
/* Updated: 2023/10/18 15:01:18 by hecmarti ### ########.fr */
/* */
/* ************************************************************************** */
#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)
return (NULL);
count = 0;
while (count < len)
{
tab[count] = s[start + count];
count++;
}
tab[count] = '\0';
return (tab);
}
/*
int main(void)
{
char const *s;
unsigned int start;
size_t len;
s = "quiero que saques ya algo";
start = 1;
len = 9;
ft_putstr_fd(ft_substr(s, start, len), 1);
return (0);
}
*/