-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.c
82 lines (67 loc) · 1.42 KB
/
string.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
#include "string.h"
int strcmp(IN CHAR16 *a, IN CHAR16 *b)
{
int i = 0;
while (a[i] != 0)
{
if (a[i] != b[i])
{
return 0;
}
i++;
}
return 1;
}
int strtoint(IN CHAR16 *source)
{
int result = 0;
int firstpos = 0;
for (int i = 0; source[i] != 0; i++)
firstpos = i;
int isminus = 0;
int j = 0;
for (int i = firstpos; i >= 0; i--)
{
if (i == firstpos && source[i] == '-')
{
isminus = 1;
continue;
}
if (source[i] < L'0' || source[i] > L'9')
break;
result += (source[i] - L'0') * intpow(10, j);
j++;
}
if (isminus)
result *= -1;
return result;
}
int getintdigit(int input)
{
for (int i = 1;; i++)
{
if ((int)((unsigned long)input % ulongpow(10, i)) == input)
return i;
}
}
int getSpecificDigitFromInt(int src, int digit)
{
return (int)((unsigned long)src % ulongpow(10, digit) / ulongpow(10, digit - 1));
}
void inttostr(int input, OUT CHAR16 *output)
{
int digit_i = 0;
if (input < 0)
{
output[0] = L'-';
input = intabs(input);
digit_i++;
}
for (int i = getintdigit(input); i > 0; i--)
{
int specific_digit = getSpecificDigitFromInt(input, i);
output[digit_i] = L'0' + specific_digit;
digit_i++;
}
output[digit_i] = 0;
}