-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
36 lines (33 loc) · 1.28 KB
/
ft_substr.c
File metadata and controls
36 lines (33 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lahamoun <lahamoun@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/14 09:28:24 by lahamoun #+# #+# */
/* Updated: 2022/11/05 17:46:40 by lahamoun ### ########.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 (start > ft_strlen(s))
len = 0;
else if (len > ft_strlen (s + start))
len = ft_strlen (s + start);
str = malloc(sizeof(char) * (len + 1));
if (str == NULL)
return (NULL);
i = 0;
while (i < len)
{
str[i++] = s[start++];
}
str[i] = '\0';
return (str);
}