-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstr_token.c
More file actions
42 lines (41 loc) · 737 Bytes
/
str_token.c
File metadata and controls
42 lines (41 loc) · 737 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 - separates strings with delimiters
* @line: It´s pointer to array we receive in getline.
* @delim: It´s characters we mark off string in parts.
* Return: A pointer to the created token
*/
char *_strtok(char *line, char *delim)
{
int j;
static char *str;
char *copystr;
if (line != NULL)
str = line;
for (; *str != '\0'; str++)
{
for (j = 0; delim[j] != '\0'; j++)
{
if (*str == delim[j])
break;
}
if (delim[j] == '\0')
break;
}
copystr = str;
if (*copystr == '\0')
return (NULL);
for (; *str != '\0'; str++)
{
for (j = 0; delim[j] != '\0'; j++)
{
if (*str == delim[j])
{
*str = '\0';
str++;
return (copystr);
}
}
}
return (copystr);
}