-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_str.c
More file actions
56 lines (51 loc) · 1.59 KB
/
print_str.c
File metadata and controls
56 lines (51 loc) · 1.59 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: guiricha <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/03/14 15:27:13 by guiricha #+# #+# */
/* Updated: 2016/03/14 16:35:21 by guiricha ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void do_norm(t_form *info, t_data *d, int *newret)
{
if (info->left == 0)
{
while (info->width - info->prec > 0)
{
if (info->zero)
ft_putchar('0');
else
ft_putchar(' ');
*newret += 1;
info->width--;
}
ft_putstr(d->string);
}
}
static void do_left(t_form *info, t_data *d, int *newret, int ret)
{
if (info->left == 1)
{
ft_putstr(d->string);
while (info->width - ret > 0)
{
ft_putchar(' ');
info->width--;
*newret += 1;
}
}
}
int print_str(t_form *info, t_data *d, int ret)
{
int newret;
newret = 0;
if (info->prec > ret || info->prec == -1)
info->prec = ret;
do_norm(info, d, &newret);
do_left(info, d, &newret, ret);
return (ret + newret);
}