-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
34 lines (31 loc) · 1.27 KB
/
ft_substr.c
File metadata and controls
34 lines (31 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sryou <sryou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/11 19:36:58 by sryou #+# #+# */
/* Updated: 2022/03/19 17:26:46 by sryou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t size;
char *mkstr;
if (s == 0)
return (0);
size = ft_strlen(s);
if (size > len + start)
size = len;
else if (size >= start)
size = size - start;
else
size = 0;
mkstr = (char *)malloc(sizeof(char) * (size + 1));
if (mkstr == 0)
return (0);
ft_strlcpy(mkstr, s + start, size + 1);
return (mkstr);
}