Добавлен файл с вспомогательными функциями
This commit is contained in:
parent
4575d0c1d2
commit
5d5fd2172c
72
func.c
Normal file
72
func.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* delay.c
|
||||||
|
*
|
||||||
|
* Created: 03.06.2023 12:34:55
|
||||||
|
* Author: Admin
|
||||||
|
*/
|
||||||
|
#include "func.h"
|
||||||
|
|
||||||
|
void delay() {
|
||||||
|
for(volatile long i = 0; i < 1000; i++){};
|
||||||
|
}
|
||||||
|
|
||||||
|
int count_digits(long number) {
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
if (number == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (number < 0) {
|
||||||
|
number = -number;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (number > 0) {
|
||||||
|
number /= 10;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void split_digits(long number, int* digits, int size) {
|
||||||
|
int digit;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
if (number == 0) {
|
||||||
|
digits[0] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (number < 0) {
|
||||||
|
number = -number;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (number > 0 && index < size) {
|
||||||
|
digit = number % 10;
|
||||||
|
digits[index] = digit;
|
||||||
|
number /= 10;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static char map(int digit) {
|
||||||
|
if (digit >= 0 && digit <= 9)
|
||||||
|
return digit + 0x09;
|
||||||
|
else
|
||||||
|
return 0x01;
|
||||||
|
}
|
||||||
|
|
||||||
|
void map_digits(char* arr, int *digits, int size) {
|
||||||
|
int idx = 0;
|
||||||
|
for (int i = size - 1; i >= 0; i--) {
|
||||||
|
arr[idx] = map(digits[i]);
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void prepare_data(char *arr, int number, int size) {
|
||||||
|
int digits[size];
|
||||||
|
split_digits(number, digits, size);
|
||||||
|
map_digits(arr, digits, size);
|
||||||
|
}
|
13
func.h
Normal file
13
func.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* delay.h
|
||||||
|
*
|
||||||
|
* Created: 03.06.2023 12:35:06
|
||||||
|
* Author: Admin
|
||||||
|
*/
|
||||||
|
|
||||||
|
void delay();
|
||||||
|
|
||||||
|
void split_digits(long number, int* digits, int size);
|
||||||
|
int count_digits(long number);
|
||||||
|
void map_digits(char* arr, int *digits, int size);
|
||||||
|
void prepare_data(char *arr, int number, int size);
|
Loading…
Reference in New Issue
Block a user