-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_substr copy.c
49 lines (44 loc) · 1.46 KB
/
ft_substr copy.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: snocita <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 16:52:47 by snocita #+# #+# */
/* Updated: 2023/01/13 12:44:01 by snocita ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
// #include <stdio.h>
/*
Substract a string
*/
size_t ft_strlen(const char *s);
char *ft_substr(char const *s, unsigned int start, size_t len);
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
char *strcpy;
i = 0;
if (len > ft_strlen(s))
{
strcpy = malloc(sizeof(char) * ft_strlen(s) + 1);
if (!strcpy)
return (NULL);
}
else
{
strcpy = malloc(sizeof(char) * len + 1);
if (!strcpy)
return (NULL);
}
while (start < ft_strlen(s) && i < len)
{
strcpy[i] = s[start];
i++;
start++;
}
strcpy[i] = '\0';
return (strcpy);
}