-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_str.c
More file actions
56 lines (50 loc) · 1.77 KB
/
ft_printf_str.c
File metadata and controls
56 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
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dporhomo <dporhomo@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/06 22:11:03 by dporhomo #+# #+# */
/* Updated: 2025/12/09 10:37:29 by dporhomo ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_putstr_padding(const char *str, t_layout *tab, t_flags flags);
int ft_print_str(const char *str, t_flags flags)
{
int count;
t_layout tab;
count = 0;
if (!str && flags.precision >= 0 && flags.precision < 6)
{
count += ft_print_padding(flags.width, 0, 0);
return (count);
}
if (!str)
str = "(null)";
tab.len = ft_strlen(str);
if (flags.precision >= 0 && flags.precision < tab.len)
tab.len = flags.precision;
tab.zeros = 0;
tab.sign = 0;
count += ft_putstr_padding(str, &tab, flags);
return (count + tab.len);
}
static int ft_putstr_padding(const char *str, t_layout *tab, t_flags flags)
{
int count;
int i;
count = 0;
i = 0;
if (flags.left == 0)
count += ft_print_padding(flags.width, tab->len, 0);
while (i < tab->len)
{
write(1, &str[i], 1);
i++;
}
if (flags.left == 1)
count += ft_print_padding(flags.width, tab->len, 0);
return (count);
}