-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
40 lines (38 loc) · 1.28 KB
/
ft_substr.c
File metadata and controls
40 lines (38 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
35
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ewang <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/22 12:01:09 by ewang #+# #+# */
/* Updated: 2022/12/01 11:48:13 by ewang ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
size_t x;
char *s1;
char *new;
i = 0;
x = 0;
s1 = (char *)s;
if (!s)
return (NULL);
if (start >= ft_strlen(s1))
return (ft_strdup(""));
while (i < len && s1[start + i])
i++;
new = malloc(i + 1);
if (!new)
return (0);
while (x < i)
{
new[x] = s1[start + x];
x++;
}
new[x] = '\0';
return (new);
}