-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_s.c
60 lines (55 loc) · 1.9 KB
/
ft_printf_s.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
56
57
58
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_s.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bnidia <bnidia@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/04 18:07:41 by bnidia #+# #+# */
/* Updated: 2022/05/21 05:21:26 by bnidia ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_fprintf.h"
#if defined(__linux__) || defined(linux) || defined(__linux)
# define LINUX 1
#else
# define LINUX 0
#endif
int ft_print_out(t_pf *z);
int output_of_finite_spaces(t_pf *z, int numlen, int signlen);
int output_of_initial_spaces(t_pf *z, int numlen, int signlen);
static void null_exception(t_pf *z);
int ft_s(t_pf *z, const char *str)
{
int i;
int strlen;
i = 0;
if (str == NULL)
{
null_exception(z);
return (0);
}
strlen = (int)ft_strlen(str);
if (z->precision != -1 && z->precision < strlen)
strlen = z->precision;
output_of_initial_spaces(z, strlen, 0);
if (z->precision > strlen || z->precision == -1)
z->precision = strlen;
while (str[i] && i < z->precision)
{
z->s[z->s_i++] = str[i++];
if (ft_print_out(z) == -1)
return (-1);
}
output_of_finite_spaces(z, z->precision, 0);
return (0);
}
static void null_exception(t_pf *z)
{
if ((z->precision > 5 || z->precision == -1) && LINUX)
ft_s(z, "(null)");
else if (z->precision != 0 && !LINUX)
ft_s(z, "(null)");
else
ft_s(z, "");
}