-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumbers_width.c
More file actions
83 lines (76 loc) · 2.28 KB
/
Copy pathnumbers_width.c
File metadata and controls
83 lines (76 loc) · 2.28 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
72
73
74
75
76
77
78
79
80
81
82
83
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* numbers_width.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pgomez-a <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/11 08:45:11 by pgomez-a #+# #+# */
/* Updated: 2021/03/12 12:48:11 by pgomez-a ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void posw_neg_int(int verif, char **number, char **width, int **result)
{
char *aux;
int num;
aux = ft_strdup(*number + 1);
num = ft_atoi(*width) - ft_strlen(*number);
if (verif != 1)
ft_putchar_fd('-', 1);
while (num > 0)
{
if (*(*number + 1) != '0' && verif != 1)
ft_putchar_fd('0', 1);
else
ft_putchar_fd(' ', 1);
(**result) += 1;
num--;
}
if (verif == 1)
ft_putchar_fd('-', 1);
(**result) += 1;
ft_putstr_fd(aux, 1);
(**result) += ft_strlen(aux);
free(aux);
}
void man_pos_width(int verif, char **number, char **width, int **result)
{
int num;
if (**number == '-' && (**width) == '0')
posw_neg_int(verif, number, width, result);
else
{
num = ft_atoi((*width)) - (int)ft_strlen(*number);
while (num > 0)
{
if (**width == '0' && **number != '0' && verif != 1)
ft_putchar_fd('0', 1);
else if (**width == '0' && ft_atoi(*number) == 0
&& ft_strlen(*number) == 1 && verif != 1)
ft_putchar_fd('0', 1);
else
ft_putchar_fd(' ', 1);
(**result) += 1;
num--;
}
ft_putstr_fd(*number, 1);
(**result) += ft_strlen(*number);
}
}
void man_neg_width(char **number, char **width, int **result)
{
char *aux;
int num;
aux = ft_strchr(*width, '-');
aux++;
num = ft_atoi(aux) - ft_strlen(*number);
ft_putstr_fd(*number, 1);
(**result) += ft_strlen(*number);
while (num > 0)
{
ft_putchar_fd(' ', 1);
(**result) += 1;
num--;
}
}