-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_print_chars.c
77 lines (70 loc) · 1.91 KB
/
ft_print_chars.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_chars.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mohaben- <mohaben-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/20 16:25:02 by mohaben- #+# #+# */
/* Updated: 2024/11/27 16:54:52 by mohaben- ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putchar(char c, int *count)
{
write(1, &c, 1);
(*count)++;
}
void ft_putchar_bns(char c, int *count, t_flags flag)
{
int width;
char padding;
width = flag.width - 1;
padding = ' ';
if (flag.zero_padding && !flag.left_align)
padding = '0';
if (flag.left_align)
{
ft_putchar(c, count);
print_loop(padding, width, count);
}
else
{
print_loop(padding, width, count);
ft_putchar(c, count);
}
}
void ft_putstr(char *s, int len, int *count)
{
while (*s && len)
{
ft_putchar(*s, count);
s++;
len--;
}
}
void ft_putstr_bns(char *s, int *count, t_flags flag)
{
int width;
int len;
char padding;
if (s == NULL)
s = "(null)";
len = ft_strlen(s);
if (flag.precision >= 0 && len > flag.precision)
len = flag.precision;
width = flag.width - len;
padding = ' ';
if (flag.zero_padding && !flag.left_align)
padding = '0';
if (flag.left_align)
{
ft_putstr(s, len, count);
print_loop(padding, width, count);
}
else
{
print_loop(padding, width, count);
ft_putstr(s, len, count);
}
}