Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Philosophers-42
Path: blob/master/philo/ft_substr.c
882 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ft_substr.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: yabtaour <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/05/19 22:14:58 by yabtaour #+# #+# */
9
/* Updated: 2022/05/19 22:15:00 by yabtaour ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
#include "philosophers.h"
13
14
char *ft_substr(char *s, int start, size_t len)
15
{
16
char *ptr;
17
unsigned int i;
18
int end;
19
20
i = 0;
21
end = len + start;
22
if (!s)
23
return (NULL);
24
ptr = (char *)malloc((len + 1) * sizeof(char));
25
if (!ptr)
26
return (NULL);
27
if (start <= ft_strlen(s))
28
{
29
while (start < end && s[start] != '\0')
30
{
31
ptr[i] = s[start];
32
i++;
33
start++;
34
}
35
}
36
ptr[i] = '\0';
37
return (ptr);
38
}
39
40