-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
51 lines (44 loc) · 1.48 KB
/
ft_substr.c
File metadata and controls
51 lines (44 loc) · 1.48 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
41
42
43
44
45
46
47
48
49
50
51
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thfranco <thfranco@student.42.rio> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 11:30:59 by thfranco #+# #+# */
/* Updated: 2023/11/04 11:31:01 by thfranco ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
unsigned int i;
char *str;
if (!s)
return (NULL);
if (ft_strlen(s) < start)
{
str = malloc(sizeof(char) * 1);
if (!(str))
return (NULL);
str[0] = '\0';
return (str);
}
str = malloc(sizeof(char) * (len + 1));
if (!str)
return (NULL);
i = 0;
while (i < len)
str[i++] = s[start++];
str[i] = '\0';
return (str);
}
/*int main(void)
{
char src[] = "substr function Implementation";
int m = 7;
int n = 12;
char* dest = ft_substr(src, m, n);
printf("%s\n", dest);
return 0;
}*/