-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
37 lines (34 loc) · 1.25 KB
/
ft_substr.c
File metadata and controls
37 lines (34 loc) · 1.25 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
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pruthann <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/14 15:46:33 by pruthann #+# #+# */
/* Updated: 2020/11/14 15:47:58 by pruthann ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *str;
unsigned int i;
i = 0;
if (!s)
return (0);
str = malloc(sizeof(*str) * (len + 1));
if (str == 0)
return (0);
if (start >= ft_strlen(s))
str[i] = '\0';
else
while (s[start] && len != i)
{
str[i] = s[start];
i++;
start++;
}
str[i] = '\0';
return (str);
}