-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_print_string.c
50 lines (45 loc) · 1.64 KB
/
ft_print_string.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amoussai <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/01 10:54:16 by amoussai #+# #+# */
/* Updated: 2019/12/13 17:43:45 by amoussai ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
int print_string(char *str, t_vars *elts)
{
int len;
int to_check;
if (elts->prec == -1)
elts->prec = INT_MAX;
if (str == NULL)
str = "(null)";
len = ft_strlen(str);
to_check = elts->len;
len = len < elts->prec ? len : elts->prec;
elts->len -= len;
print_padding(elts, 0, 0);
while (*str && elts->prec--)
ft_putchar_fd(*str++, 1);
print_padding(elts, 1, 0);
return (len > to_check ? len : to_check);
}
int print_character(char str, t_vars *elts)
{
int len;
int to_check;
if (elts->prec == -1)
elts->prec = INT_MAX;
len = 1;
to_check = elts->len;
len = len < elts->prec ? len : elts->prec;
elts->len -= len;
print_padding(elts, 0, 0);
ft_putchar_fd(str, 1);
print_padding(elts, 1, 0);
return (len > to_check ? len : to_check);
}