-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_utils.c
55 lines (49 loc) · 1.85 KB
/
ft_printf_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvarodi <vvarodi@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/14 00:17:54 by vvarodi #+# #+# */
/* Updated: 2020/08/19 10:05:41 by vvarodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
size_t ft_strlen(const char *s)
{
size_t i;
i = 0;
while (s[i] != '\0')
i++;
return (i);
}
void ft_bzero(void *s, size_t n)
{
unsigned char *str;
str = (unsigned char *)s;
while (n--)
*str++ = '\0';
}
char *conversion_helper(t_buffer *b, t_flags *f, char *str, char type)
{
if (f->b_left_aligned == 1 && f->b_zero_padding == 1)
f->b_zero_padding = 0;
if ((f->b_preci == 1 || f->b_preci == 2) && f->precision >= f->to_write)
f->zeros = f->precision - f->to_write;
else if (f->b_preci == 2 && f->precision == 0 && f->b_num_zero == 1)
f->to_write = 0;
if (!f->b_left_aligned && type != 'p')
f->width = f->width - f->to_write - f->zeros;
if (!f->b_left_aligned && type == 'p')
f->width = f->width - f->to_write - f->zeros - 2;
if (f->b_zero_padding && !f->b_left_aligned && f->b_preci == 0)
{
while (f->width > 0)
add_to_buffer(b, f, '0');
}
else if (!f->b_left_aligned)
while (f->width > 0)
add_to_buffer(b, f, ' ');
return (str);
}