-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_func.c
71 lines (62 loc) · 1.55 KB
/
print_func.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yohwang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/09 15:35:27 by yohwang #+# #+# */
/* Updated: 2022/06/09 15:41:11 by yohwang ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void print_word(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
write(1, str + i++, 1);
}
long long count_len(long long n)
{
long long len;
len = 1;
while (n / 10 > 0)
{
len++;
n = n / 10;
}
return (len - 1);
}
long long calc_len(long long len)
{
long long ten;
ten = 1;
while (len-- > 0)
ten = ten * 10;
return (ten);
}
void print_num(int n)
{
char c;
long long num;
long long len;
if (n < 0)
{
c = '-';
write(1, &c, 1);
num = -1LL * n;
}
else
num = n;
len = count_len(num);
while (len > 0)
{
c = num / calc_len(len) + '0';
write(1, &c, 1);
num = num % calc_len(len);
len--;
}
c = num + '0';
write(1, &c, 1);
}