-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_substr.c
35 lines (32 loc) · 1.29 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: ksmorozo <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/11/03 13:31:41 by ksmorozo #+# #+# */
/* Updated: 2021/07/07 12:20:36 by ksmorozo ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *substr;
unsigned int count;
substr = (char *)malloc(len + 1);
if (substr == NULL)
return (NULL);
if ((unsigned int)ft_strlen(s) <= start)
return (substr);
count = 0;
while (s[start] != '\0' && count < len)
{
substr[count] = s[start];
count++;
start++;
}
substr[count] = '\0';
return (substr);
}