-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putstr.c
83 lines (78 loc) · 2.1 KB
/
ft_putstr.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
81
82
83
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fulloa-s <fulloa-s@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/02 14:47:09 by fulloa-s #+# #+# */
/* Updated: 2021/02/09 11:31:19 by fulloa-s ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putstr_minus(char *str, t_list *list, int i, int s)
{
if (list->num_m)
ft_putchar('-', list);
while (i < set_precision(str, list, s))
{
ft_putchar(str[i], list);
i++;
s = 1;
}
s = 2;
list->width -= set_precision(str, list, s);
while (list->width > 0)
{
ft_putchar(' ', list);
list->width--;
}
}
void ft_putstr_zero(char *str, t_list *list, int s)
{
s = 3;
if (list->num_m && list->flag_zero && list->precision <= -1)
ft_putchar('-', list);
list->width -= set_precision(str, list, s);
while (list->width > 0)
{
if (list->flag_zero && list->precision <= -1)
ft_putchar('0', list);
else
ft_putchar(' ', list);
list->width--;
}
if (list->type == 'p')
{
ft_putchar('0', list);
ft_putchar('x', list);
}
if (list->num_m && list->flag_zero && list->precision > -1)
ft_putchar('-', list);
if (list->num_m && !list->flag_zero)
ft_putchar('-', list);
}
void ft_putstr(char *str, t_list *list)
{
int i;
int s;
if (!str)
str = "(null)";
i = 0;
if (list->flag_minus == 1)
{
s = 0;
ft_putstr_minus(str, list, i, s);
}
else
{
ft_putstr_zero(str, list, i);
s = 0;
while (i < set_precision(str, list, s))
{
ft_putchar(str[i], list);
i++;
s = 1;
}
}
}