-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_str.c
51 lines (45 loc) · 1.67 KB
/
print_str.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ldulling <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/22 19:27:17 by ldulling #+# #+# */
/* Updated: 2023/10/22 19:27:18 by ldulling ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int print(const char *str, int len, t_struct *f);
int print_str(const char *str, t_struct *f)
{
int len;
int printed;
printed = 0;
if (!str)
{
len = ft_strlen(NULL_PRINTOUT_STR);
if (f->precision >= 0 && len > f->precision)
len = 0;
printed += print(NULL_PRINTOUT_STR, len, f);
}
else
{
len = ft_strlen(str);
if (f->precision >= 0 && len > f->precision)
len = f->precision;
printed += print(str, len, f);
}
return (printed);
}
static int print(const char *str, int len, t_struct *f)
{
int printed;
printed = 0;
if (!f->minus && f->width > len)
printed += ft_putnchar_fd(' ', f->width - len, FD);
printed += ft_putnstr_fd((char *) str, len, FD);
if (f->minus && f->width > len)
printed += ft_putnchar_fd(' ', f->width - len, FD);
return (printed);
}