forked from hidaehyunlee/Libft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strtok.c
More file actions
41 lines (38 loc) · 1.25 KB
/
ft_strtok.c
File metadata and controls
41 lines (38 loc) · 1.25 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_strtok.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: daelee <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/27 15:54:48 by daelee #+# #+# */
/* Updated: 2020/12/27 15:55:01 by daelee ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtok(char *str, char sepa)
{
static char *stock = NULL;
char *ptr;
int i;
i = 0;
ptr = NULL;
if (str != NULL)
stock = ft_strdup(str);
while (*stock != '\0')
{
if (i == 0 && *stock != sepa)
{
i = 1;
ptr = stock;
}
else if (i == 1 && *stock == sepa)
{
*stock = '\0';
stock += 1;
break ;
}
stock++;
}
return (ptr);
}