-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_strtok.c
More file actions
42 lines (39 loc) · 763 Bytes
/
_strtok.c
File metadata and controls
42 lines (39 loc) · 763 Bytes
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
#include "shell.h"
/**
* _strtok - custom made strtok function
* @str: the string to be tokenized
* @delimiter: the delimters to watch out for
* Return: the tonized string
*/
char *_strtok(char *str, const char *delimiter)
{
static char *buffer; /* unchanging variable */
char *token;
int i = 0, j = 0, is_found; /* length = _strlen(delimiter); */
if (str)
buffer = str;
if (buffer == NULL || *buffer == '\0')
return (NULL);
token = buffer;
while (buffer[i] != '\0')
{
is_found = 0;
for (j = 0; delimiter[j] != '\0'; j++)
{
if (buffer[i] == delimiter[j])
{
is_found = 1;
break;
}
}
if (is_found)
{
buffer[i] = '\0';
buffer = buffer + i + 1;
return (token);
}
i++;
}
buffer = NULL;
return (token);
}