-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strisplit.c
39 lines (36 loc) · 1.31 KB
/
ft_strisplit.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strisplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rnbou <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/17 18:52:21 by rnbou #+# #+# */
/* Updated: 2018/10/17 19:37:11 by rnbou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_slrisplit(char *str, size_t n)
{
char **s;
size_t i;
if (n >= ft_strlen(str))
return (NULL);
s = (char **)malloc(sizeof(char *) * 2);
s[0] = (char *)malloc(sizeof(char) * (n + 1));
s[0][n] = '\0';
i = 0;
while (i < n)
{
s[1][i] = str[i];
i++;
}
s[2] = (char *)malloc(sizeof(char) * (ft_strlen(str) - n + 1));
while (str[i] != '\0')
{
s[1][i - n] = str[i];
i++;
}
s[1][i - n] = '\0';
return (s);
}