-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_type.c
More file actions
55 lines (50 loc) · 1.77 KB
/
Copy pathprint_type.c
File metadata and controls
55 lines (50 loc) · 1.77 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_prints.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lpetsoan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/04 16:40:43 by lpetsoan #+# #+# */
/* Updated: 2019/07/12 12:29:32 by lpetsoan ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void print(char *s, int max)
{
while (max-- != 0)
ft_putchar(*s++);
}
/* This function prints the first few parameters such as d and s */
void print_type(t_specifier *spec, char *val)
{
int field;
int max_width;
char padding;
padding = ' ';
field = 1;
max_width = ft_strlen(val);
/* Check if the field width was set */
if (spec->field_width != NULL)
field = ft_atoi(spec->field_width);
// check if the max width was set
if (spec->max_width != NULL)
max_width = ft_atoi(spec->max_width);
// check if the padding with zeo flag was set.
if (spec->flag & 1)
padding = '0';
if (spec->flag & (1 << 3))
if (val[0] != '-' && ft_isdigit(val[1]))
ft_putchar(spec->flag & (1 << 4) ? '+' : ' ');
field -= ft_strlen(val);
if (spec->flag & (1 << 1))
{
spaces(field, padding);
print(val, max_width);
}
else
{
print(val, max_width);
spaces(field, padding);
}
}