-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelper_func2.c
More file actions
100 lines (90 loc) · 1.19 KB
/
helper_func2.c
File metadata and controls
100 lines (90 loc) · 1.19 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
#include "shell.h"
/**
* get_variable - .
* @name: .
* @head: .
* Return: .
*/
list_path *get_variable(char *name, list_path *head)
{
while (head)
{
if (_varcmp(name, head->path))
return (head);
head = head->next;
}
return (NULL);
}
/**
* _varcmp - .
* @var_name: .
* @full_var: .
* Return: .
*/
int _varcmp(char *var_name, char *full_var)
{
int i;
for (i = 0; var_name[i]; i++)
{
if (full_var[i])
if (var_name[i] - full_var[i] != 0)
return (-1);
}
if (full_var[i] == '=')
return (0);
return (-1);
}
/**
* num_to_char - .
* @num: .
* Return: .
*/
char *num_to_char(int num)
{
/*count digits*/
int c = 0, tmp = num;
char *cp_num;
if (num == 0)
{
c = 1;
}
else
{
while (tmp != 0)
{
tmp /= 10;
c++;
}
}
cp_num = malloc(sizeof(char) * (c + 1));
if (!cp_num)
{
perror("malloc");
return (NULL);
}
cp_num[c] = '\0';
while (c != 0)
{
c--;
cp_num[c] = '0' + num % 10;
num /= 10;
}
return (cp_num);
}
/**
* char_count_piped - .
* @str: .
* @c: .
* Return: .
*/
unsigned int char_count_piped(char *str, char c)
{
unsigned int count = 0;
while (*str != '\0')
{
if (*str == c)
count++;
str++;
}
return (count + 1);
}