Flipper/Applications/Official/source-OLDER/xMasterX/usb_hid_autofire/tools.c

57 lines
840 B
C
Raw Normal View History

2023-01-26 07:52:38 +00:00
//
// 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;
}