-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
33 lines (30 loc) · 1.27 KB
/
ft_substr.c
File metadata and controls
33 lines (30 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: muganiev <gf.black.tv@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/26 15:14:25 by muganiev #+# #+# */
/* Updated: 2022/06/04 22:42:28 by muganiev ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *ptr;
unsigned int len_s;
if (!s)
return (0);
len_s = (unsigned int)ft_strlen(s);
if (len > len_s)
len = len_s - start;
if (start >= len_s)
return (ft_strdup(""));
ptr = malloc (sizeof(char) * (len + 1));
if (!ptr)
return (0);
ft_memcpy(ptr, s + start, len);
ptr[len] = '\0';
return (ptr);
}