-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_substr.c
More file actions
41 lines (38 loc) · 1.34 KB
/
ft_substr.c
File metadata and controls
41 lines (38 loc) · 1.34 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
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aycami <aycami@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/07 14:55:18 by aycami #+# #+# */
/* Updated: 2024/10/07 14:55:26 by aycami ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
size_t j;
char *final;
if (s)
{
if (start >= ft_strlen(s) || len == 0 || ft_strlen(s) == 0)
return (ft_strdup(""));
i = 0;
while (i < len && s[i + start])
i++;
final = (char *) malloc((sizeof(char) * i) + 1);
if (!(final))
return (NULL);
j = 0;
while (j < i)
{
final[j] = s[start + j];
j++;
}
final[j] = '\0';
return (final);
}
return (NULL);
}