-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_strtok.c
40 lines (39 loc) · 796 Bytes
/
_strtok.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
#include "shell.h"
/**
* _strtok - tokenize a string
* @str: string to tokenize
* @delim: delimiter string
*
* Return: pointer to a token
*/
char *_strtok(char *str, char *delim)
{
static char *placeholder;
static char oldchar;
char *token;
char *d_cpy = delim;
if (str != NULL)
placeholder = str;
else if (oldchar == '\0')
return (NULL);
for (; *placeholder != '\0'; placeholder++)
{
for (d_cpy = delim; *d_cpy && *d_cpy != *placeholder; d_cpy++)
;
if (*d_cpy == '\0')
break;
}
if (*placeholder == '\0')
return (NULL);
token = placeholder;
for (; *placeholder != '\0'; placeholder++)
{
for (d_cpy = delim; *d_cpy && *d_cpy != *placeholder; d_cpy++)
;
if (*d_cpy != '\0')
break;
}
oldchar = *placeholder;
*placeholder++ = '\0';
return (token);
}