PatchworkOS
Loading...
Searching...
No Matches
lltoa.c
Go to the documentation of this file.
1
#include <
stdbool.h
>
2
#include <
stdlib.h
>
3
4
#include "
common/digits.h
"
5
6
char
*
lltoa
(
long
long
int
value,
char
* str,
int
base)
7
{
8
if
(value == 0)
9
{
10
str[0] =
'0'
;
11
str[1] =
'\0'
;
12
return
str;
13
}
14
15
bool
isNegative =
false
;
16
if
(value < 0)
17
{
18
isNegative =
true
;
19
value = -value;
20
}
21
22
int
i = 0;
23
while
(value != 0)
24
{
25
int
remainder
= value % base;
26
str[i++] = (
remainder
< 10) ?
remainder
+
'0'
:
remainder
+
'a'
- 10;
27
value = value / base;
28
}
29
30
if
(isNegative)
31
{
32
str[i++] =
'-'
;
33
}
34
35
str[i] =
'\0'
;
36
37
int
start
= 0;
38
int
end = i - 1;
39
while
(
start
< end)
40
{
41
char
temp = str[
start
];
42
str[
start
] = str[end];
43
str[end] = temp;
44
start
++;
45
end--;
46
}
47
48
return
str;
49
}
digits.h
lltoa
char * lltoa(long long int value, char *str, int base)
Definition
lltoa.c:6
remainder
double remainder(double x, double y)
start
static void start()
Definition
main.c:542
stdbool.h
stdlib.h
src
libstd
functions
stdlib
lltoa.c
Generated by
1.9.8