-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_func.c
More file actions
103 lines (94 loc) · 1.59 KB
/
Copy pathcustom_func.c
File metadata and controls
103 lines (94 loc) · 1.59 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "main.h"
/**
* free_token_array - Its free memory adresses
* @tokens: list of array to free
*
* Return: no return value;
*/
void free_token_array(char **tokens)
{
int i = 0;
while (tokens[i] != NULL)
{
free(tokens[i]);
i++;
}
free(tokens);
}
/**
* _getpath - get the environment PATH value
* @str: path variable to get
*
* Return: return the path value
*/
char *_getpath(char *str)
{
int a = 0;
char *tk, *encpy, *rst = NULL;
while (environ[a])
{
encpy = strdup(environ[a]);
tk = strtok(encpy, "=");
if (_strcmp(tk, str) == 0)
rst = strdup(strtok(NULL, "="));
free(encpy);
a++;
}
return (rst);
}
/**
* comment_handler - handle the comment pass to args
* @source: string of argument
* Return: No return value
*/
void comment_handler(char *source)
{
int i = 0;
while (source[i] != '\0')
{
if (i > 0 && source[i] == '#' && source[i - 1] != ' ')
break;
if (source[i] == '#')
{
source[i] = '\0';
break;
}
i++;
}
}
/**
* word_len - function to count number of letters of
* each word
* @str: word
* Return: number of letters of tje word
**/
int word_len(char *str)
{
int index = 0, len = 0;
while (*(str + index) && *(str + index) != ' ')
{
len++;
index++;
}
return (len);
}
/**
* count_words - functin to count number of words
* @str: string
* Return: number of words
**/
int count_words(char *str)
{
int index = 0, words = 0, len = 0;
for (index = 0; *(str + index); index++)
len++;
for (index = 0; index < len; index++)
{
if (*(str + index) != ' ')
{
words++;
index += word_len(str + index);
}
}
return (words);
}