-
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: cwesseli <cwesseli@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/10/12 15:51:21 by cwesseli #+# #+# */
/* Updated: 2022/10/20 15:54:03 by cwesseli ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *ptr;
unsigned int ls;
ls = ft_strlen((char *) s);
if (ls - start < len)
len = ls - start;
if (!s || ls < start)
{
ptr = malloc(sizeof(char) * 1);
ptr[0] = '\0';
return (ptr);
}
ptr = malloc(sizeof(char) * (len + 1));
if (!ptr)
return (NULL);
ft_strlcpy(ptr, s + start, len + 1);
return (ptr);
}