-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.c
More file actions
71 lines (66 loc) · 1.68 KB
/
print.c
File metadata and controls
71 lines (66 loc) · 1.68 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* ************************************************************************** */
/* */
/* :::::::: */
/* print.c :+: :+: */
/* +:+ */
/* By: nsterk <nsterk@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/12/14 13:13:36 by nsterk #+# #+# */
/* Updated: 2020/12/29 18:18:01 by nsterk ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
#include <unistd.h>
static void print_argument_char(t_tab *tab)
{
int i;
i = 1;
if (tab->left_justify)
{
write(1, tab->argument, 1);
while (i < tab->width)
{
write(1, &" ", 1);
i++;
}
}
else
{
while (i < tab->width)
{
write(1, &" ", 1);
i++;
}
write(1, tab->argument, 1);
}
tab->ret += i;
}
int print_argument(t_tab *tab)
{
if (tab->specifier == 'c')
{
if (tab->width > 1)
print_argument_char(tab);
else
{
write(1, tab->argument, 1);
tab->ret++;
}
}
else
{
ft_putstr_fd(tab->argument, 1);
tab->ret += (int)ft_strlen(tab->argument);
}
if (tab->argument)
free(tab->argument);
re_initialize(tab);
return (tab->ret);
}
int print_char(t_tab *tab)
{
write(1, tab->format, 1);
tab->ret++;
tab->format++;
return (tab->ret);
}