-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strsub.c
42 lines (39 loc) · 1.3 KB
/
ft_strsub.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nahmed-m <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/30 04:21:03 by nahmed-m #+# #+# */
/* Updated: 2015/12/10 11:55:48 by nahmed-m ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strsub(char const *s, unsigned int start, size_t len)
{
unsigned int i;
unsigned int j;
unsigned int k;
char *str;
i = 0;
k = 0;
while (i != start)
i++;
if ((str = (char*)malloc(sizeof(char) * len + 1)) == NULL)
return (NULL);
if (i == start)
{
j = i;
while (j < len + i)
{
str[k] = s[j];
j++;
k++;
}
str[k] = '\0';
return (str);
}
return (str);
}