-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools2.c
136 lines (109 loc) · 1.99 KB
/
tools2.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "holberton.h"
/**
* reverse_array - reverses an array of integers
*
* @a: The array of int to be reversed
* @n: The length of the array
*
*/
void reverse_array(int *a, int n)
{
int aux, i;
n = n - 1;
for (i = 0; i <= (n / 2); i++)
{
aux = a[i];
a[i] = a[n - i];
a[n - i] = aux;
}
}
/**
* rev_string - reverse a String in its address memory
*
* @s: The string to be reversed
*
*/
void rev_string(char *s)
{
int i, lenght;
char auxString[1000];
i = 0;
while (s[i] != 0)
{
auxString[i] = s[i];
i++;
}
lenght = i - 1;
for (i = 0; i <= lenght; i++)
*(s + i) = auxString[lenght - i];
}
/**
* _strcmp - compares digit by digit of two strings
*
* @s1: First string
* @s2: Second string
*
* Return: The ASCII substract of the different firs digit found
*/
int _strcmp(char *s1, char *s2)
{
int i, n = 0;
for (i = 0; s1[i] != 0; i++)
{
if (s1[i] != s2[i])
{
n = s1[i] - s2[i];
return (n);
}
}
return (n);
}
/**
* hex_maker - converts an array of ints to hex
*
* @hex: The int array
* @j: The size of the array
*
* Return: The ASCII substract of the different firs digit found
*/
char *hex_maker(int *hex, int j)
{
int i;
char *hex_char;
hex_char = malloc((j + 1) * sizeof(char));
if (hex_char == NULL)
exit(1);
for (i = 0; i < j; i++)
{
if (*(hex + i) >= 0 && *(hex + i) <= 9)
*(hex_char + i) = *(hex + i) + 48;
else if (*(hex + i) == 10)
*(hex_char + i) = 'a';
else if (*(hex + i) == 11)
*(hex_char + i) = 'b';
else if (*(hex + i) == 12)
*(hex_char + i) = 'c';
else if (*(hex + i) == 13)
*(hex_char + i) = 'd';
else if (*(hex + i) == 14)
*(hex_char + i) = 'e';
else if (*(hex + i) == 15)
*(hex_char + i) = 'f';
}
*(hex_char + i) = '\0';
return (hex_char);
}
/**
* upper - capitalizes an array
*
* @string: The hex string
*/
void upper(char *string)
{
int i;
for (i = 0; *(string + i); i++)
{
if (*(string + i) >= 97 && *(string + i) <= 102)
*(string + i) = *(string + i) - 32;
}
}