-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_print_string_type.c
56 lines (50 loc) · 1.05 KB
/
ft_print_string_type.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
#include "ft_printf.h"
int ft_strlen(char *str)
{
int i;
if (!str)
return (0);
i = 0;
while (str[i])
i++;
return (i);
}
int ft_print_string_width(t_arg_param param, int len, int print_c)
{
char width_c;
width_c = ' ';
if (FLG_NULL & param.flag)
width_c = '0';
param.width -= len;
print_c += param.width;
while (param.width--)
write(1, &width_c, 1);
return (print_c);
}
int ft_print_string_type(t_arg_param param, va_list *arg_ptr)
{
int print_c;
int len;
char *str;
print_c = 0;
str = va_arg(*arg_ptr, char *);
if (str == NULL)
str = "(null)";
len = ft_strlen(str);
if (param.precision != -1 && param.precision < len)
len = param.precision;
if (!(param.flag & FLG_MINUS) && (param.width > len))
print_c = ft_print_string_width(param, len, print_c);
len = -1;
while (str[++len])
{
if (param.precision == len)
break ;
write(1, &(str[len]), 1);
++print_c;
}
if ((param.width > len) && (param.flag & FLG_MINUS)
&& (param.flag &= ~FLG_NULL))
print_c = ft_print_string_width(param, len, print_c);
return (print_c);
}