-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_utils2.c
80 lines (71 loc) · 1.75 KB
/
ft_printf_utils2.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_printf_utils2.c :+: :+: */
/* +:+ */
/* By: rbakker <rbakker@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2019/12/19 17:30:51 by rbakker #+# #+# */
/* Updated: 2020/01/13 12:36:55 by rbakker ######## odam.nl */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int hex_len(unsigned long value)
{
int division;
int number;
number = 0;
if (value == 0)
return (1);
while (value != 0)
{
division = value % 16;
number++;
value = value / 16;
}
return (number);
}
int integer_len(long long n)
{
int count;
count = 0;
if (n == 0)
count++;
if (n < 0)
count++;
while (n != 0)
{
n = n / 10;
count++;
}
return (count);
}
void write_negative_function(int *sign, t_format *format)
{
int output;
output = write(1, "-", 1);
if (format->output == -1 || output == -1)
{
format->output = -1;
return ;
}
format->output += output;
*sign = 2;
}
void number_zero(t_format *format)
{
int i;
int output;
i = 0;
while (i < format->width)
{
output = write(1, " ", 1);
if (format->output == -1 || output == -1)
{
format->output = -1;
return ;
}
format->output += output;
i++;
}
}