-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_substr.c
35 lines (32 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: taehkwon <taehkwon@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/21 17:07:36 by taehkwon #+# #+# */
/* Updated: 2023/06/29 20:13:59 by taehkwon ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *result;
size_t s_len;
size_t result_len;
if (!s)
return (0);
s_len = ft_strlen(s);
if (start >= s_len)
return (ft_strdup(""));
result_len = s_len - start;
if (result_len > len)
result_len = len;
result = (char *)malloc((result_len + 1) * sizeof(char));
if (!result)
return (0);
ft_memcpy(result, s + start, result_len);
result[result_len] = '\0';
return (result);
}