-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconvern.h
More file actions
62 lines (54 loc) · 1.3 KB
/
Copy pathconvern.h
File metadata and controls
62 lines (54 loc) · 1.3 KB
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
// ôóíêöèÿ ditobi() - Decrimal Integer To Binary Integer ïåðåâîäèò öåëîå ÷èñëî,
// çàäàííîå â 10-é ôîðìå, â öåëîå 2-å ÷èñëî. ïàðàìåòð num - öåëîå 10-å ÷èñëî
// äëÿ ïðåîáðàçîâàíèÿ. ïàðàìåòð s - óêàçàòåëü íà ñòðîêó ñ öåëûì 2-é ÷èñëîì.
void ditobi( int num, char* s )
{
int i = 0;
if ( num )
for( ; num!= 0; i++ )
{
if( num % 2 )
s[i] = '1';
else
s[i] = '0';
num/= 2;
}
else
s[i++] = '0';
s[i] = '\0';
}
// ôóíêöèÿ exchs() - Exchange String ïåðåïèñûâàåò ñòðîêó çàäîì íà ïåðåä.
// ïàðàìåòð str - ñòðîêà, äëÿ îáðàáîòêè.
void exchs( char *str )
{
int j, i = strlen( str ) - 1;
char sBuf[33], *s = sBuf;
for( j = 0; i > -1; j++, i-- )
s[j] = str[i];
s[j] = '\0';
sprintf( str, "%s", s );
}
// ôóíêöèÿ äîáàâëÿåò( óáèðàåò ) íóëè, ÷òîáû ñòðîêà áûëà äëèíîé â noe.
void AddZero( char* s, int noe )
{
char sBuf[80], *buf = sBuf;
int i, k = 0, j = strlen( s );
if( j > noe )
{
for( i = strlen( s )-1; k < noe; i--, k++ )
buf[k] = s[i];
buf[k] = '\0';
exchs( buf );
sprintf( s, "%s", buf );
return ;
}
else
if( j == noe )
return ;
sprintf( buf, "%s", s );
j = noe - j;
for( i = 0; i < j; i++ )
s[i] = '0';
s[i] = '\0';
strcat( s, buf );
}