-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring.c
More file actions
84 lines (69 loc) · 1.26 KB
/
Copy pathstring.c
File metadata and controls
84 lines (69 loc) · 1.26 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "header.h"
/**
* _token - Function to split a string by tokens
*
* @array: array to save all tokens
*e
* Return: string divided by token to success
*/
char *_token(char *array[])
{
char *token = NULL;
if (array[0][0] == '/' || array[0][0] == ' ')
{
if (array[0][0] == ' ')
{
token = _string_directory(array);
return (token);
}
else
{
token = array[0];
}
}
else
{
token = _string_directory(array);
}
return (token);
}
/**
* _strdup - Function that duplicate an array
* with a new apce in memory
* @str: string to duplicated
* Return: duplicated string to succes or NULL from error
*/
char *_strdup(char *str)
{
char *copy;
int index = 0, len = 0;
if (str == NULL)
return (NULL);
for (index = 0; str[index]; index++)
len++;
copy = malloc(sizeof(char) * (len + 1));
if (copy == NULL)
return (NULL);
for (index = 0; str[index]; index++)
copy[index] = str[index];
copy[len] = '\0';
return (copy);
}
/**
* _strcmp - to compare two string
*@s1: value waited from the main.c
*@s2: source to be compare
* Return: Always 0.
*/
int _strcmp(char *s1, char *s2)
{
int c = 0, x = 0;
for (c = 0; s1[c] != '\0' && s2[c] != '\0'; c++)
{
if (s1[c] == s2[c])
x = 0;
else
return (s1[c] - s2[c]);
}
return (x);
}