-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractive.c
87 lines (81 loc) · 1.97 KB
/
interactive.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
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "interactive.h"
void waitForEnter() {
while (_kbhit())
_getch();
while (_getch()!=13);
}
char choice(char variant[]) {
while (_kbhit())
_getch();
char key;
do
key = _getch();
while (!strchr(variant, key));
printf("%c\n", key);
return key;
}
char *toRU(const char *s) {
char *b = (char *)malloc(sizeof(char)*strlen(s));
unsigned int i=0;
for (i; s[i]!=0; i++)
if ((s[i]>='А')&&(s[i]<='п')) {
b[i] = s[i]+192;
} else if ((s[i]>='р')&&(s[i]<='я'))
b[i] = s[i]-16;
else if (s[i]=='№')
b[i] = -4;
else if (s[i]=='Ё')
b[i] = -16;
else if (s[i]=='ё')
b[i] = -15;
else
b[i] = s[i];
b[i] = 0;
return b;
}
char *intToStr(int n) {
const int maxlen=7;
char *str = (char *)calloc(maxlen, sizeof(char));
/*
calloc(), в отличие от malloc(), заполняет выделенную память нулями;
calloc() рассчитан на создание массивов.
*/
bool minus = (n<0)? true:false;
if (n==0)
strcpy(str, "0");
else {
int d, pos=maxlen-1;
while (n>0) {
d = n%10;
str[pos] = d+'0';
--pos;
n /= 10;
}
}
if (minus)
str[0] = '-';
while (!str[minus])
for (int i=minus; i<maxlen; i++)
str[i] = str[i+1];
return str;
}
// Возвращает true, если 3 принятых числа располагаются в порядке возрастания или убывания
bool inOrder(const int a, const int b, const int c) {
return (((a>=b)&&(b>=c))||((a<=b)&&(b<=c)));
}
// Приводит строку к нижнему регистру
char *lowerCase(char *word) {
for (int i=0; word[i]; i++)
if (inOrder('A', word[i], 'Z'))
word[i] += 'a'-'A';
else if (inOrder('А', word[i], 'Я'))
word[i] += 'а'-'А';
else if (word[i]=='Ё')
word[i] = 'ё';
return word;
}