-
Notifications
You must be signed in to change notification settings - Fork 13
/
tools.c
56 lines (44 loc) · 840 Bytes
/
tools.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
//
// Tools for USB HID Autofire
//
void strrev(char* arr, int start, int end) {
char temp;
if (start >= end)
return;
temp = *(arr + start);
*(arr + start) = *(arr + end);
*(arr + end) = temp;
start++;
end--;
strrev(arr, start, end);
}
char *itoa(int number, char *arr, int base)
{
int i = 0, r, negative = 0;
if (number == 0)
{
arr[i] = '0';
arr[i + 1] = '\0';
return arr;
}
if (number < 0 && base == 10)
{
number *= -1;
negative = 1;
}
while (number != 0)
{
r = number % base;
arr[i] = (r > 9) ? (r - 10) + 'a' : r + '0';
i++;
number /= base;
}
if (negative)
{
arr[i] = '-';
i++;
}
strrev(arr, 0, i - 1);
arr[i] = '\0';
return arr;
}