-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.c
More file actions
53 lines (46 loc) · 803 Bytes
/
function.c
File metadata and controls
53 lines (46 loc) · 803 Bytes
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
#include "function.h"
int isUint(const char* const ch)
{
unsigned int i;
if (!sLen(ch))
return 0;
for (i = 0; ch[i]; i++) {
if (ch[i] < '0' || ch[i] > '9') {
return 0;
}
}
return 1;
}
unsigned int
pow2ui(unsigned int base, unsigned int pow)
{
unsigned int i, j;
if (!base)
return 0;
if (!pow)
return 1;
for (i = 1, j = base; i < pow; i++) {
j = j * base;
}
return j;
}
unsigned int
s2ui(const char* const ch)
{
unsigned int i, j, k;
j = 0;
k = 0;
i = sLen(ch) - 1;
do {
j += (ch[i] - '0') * pow2ui(10, k++);
} while (i-- != 0);
return j;
}
unsigned int
sLen(const char* const ch)
{
unsigned int i;
for (i = 0; ch[i]; i++)
;
return i;
}