-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinters.c
56 lines (51 loc) · 1.73 KB
/
printers.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: coskelet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/05 17:05:52 by coskelet #+# #+# */
/* Updated: 2022/01/08 12:31:00 by coskelet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int char_printer(unsigned char c, t_list set)
{
char filler;
if (set.left_adjust)
putch(c);
if (set.width < 1)
set.width = 1;
filler = ' ';
if (set.zero && set.left_adjust == 0)
filler = '0';
if (set.width > 1)
print_filler(filler, set.width - 1);
if (set.left_adjust == 0)
putch(c);
return (set.width);
}
int string_printer(char *str, t_list set)
{
char filler;
size_t size;
if (str == NULL)
str = "(null)";
size = strsize(str);
if (set.dot && size > set.precision)
size = set.precision;
if (set.width < size)
set.width = size;
if (set.left_adjust)
putnstr(str, size);
if (set.dot && set.precision == 0)
return (0);
filler = ' ';
if (set.zero && set.left_adjust == 0)
filler = '0';
print_filler(filler, set.width - size);
if (set.left_adjust == 0)
putnstr(str, size);
return (size + (set.width - size));
}