-
Notifications
You must be signed in to change notification settings - Fork 0
/
important_fun.c
94 lines (80 loc) · 1.21 KB
/
important_fun.c
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
#include "shell.h"
/**
* _itoa - function that convert the num into ascii
*
* @num: the string
*
* Return: The integer
*/
char *_itoa(int num)
{
char buff[20];
int i = 0;
if (num == 0)
buff[i++] = '0';
else
{
while (num > 0)
{
buff[i++] = (num % 10) + '0';
num /= 10;
}
}
buff[i] = '\0';
rev_string(buff, i);
return (_strdup(buff));
}
/**
* rev_string - function reverse string
*
* @str: the string
*
* @len: the length
*/
void rev_string(char *str, int len)
{
char temp;
int i = 0;
int e = len - 1;
while (i < e)
{
temp = str[i];
str[i] = str[e];
str[e] = temp;
i++;
e--;
}
}
/**
* _error - function that print error
*
* @program: the shell name
*
* @commend: The name of commend
*
* @index: the index
*/
void _error(char *program, char *commend, int index)
{
char *num;
num = _itoa(index);
write(1, program, _strlen(program));
write(1, ": ", 2);
write(1, num, _strlen(num));
write(1, ": ", 2);
write(1, commend, _strlen(commend));
write(1, ": not found", 11);
free(num);
}
/**
* print_env - function that print environment
*/
void print_env(void)
{
int i;
for (i = 0; environ[i]; i++)
{
write(1, environ[i], _strlen(environ[i]));
write(1, "\n", 1);
}
}