6
6
/* By: cnascime <[email protected] > +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2022/07/20 21:51:16 by cnascime #+# #+# */
9
- /* Updated: 2022/08/06 16:51:32 by cnascime ### ########.fr */
9
+ /* Updated: 2022/08/10 07:25:11 by cnascime ### ########.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
13
13
#include "libftprintf.h"
14
14
#include "./libft/libft.h"
15
15
16
- // write(1, &"0123456789abcdef"[str[i] / 16], 1);
17
- int treatment (char character , va_list listofarguments )
16
+ // write(fd, &"0123456789abcdef"[str[i] / 16], 1);
17
+ // write(fd, &("0123456789abcdef"[str[i] / 16]), 1); testar segundo ruchoa
18
+ int treatment (int fd , char character , va_list listofarguments )
18
19
{
19
20
if (character == 'c' )
20
- return (ft_putchar_fd (va_arg (listofarguments , int ), 1 ));
21
- /* if (character == 's')
22
- return (função( va_arg(listofarguments, char *)));
23
- if (character == 'p')
24
- return (função(va_arg(listofarguments, long long unsigned int)));
21
+ return (ft_putchar_fd (fd , va_arg (listofarguments , int )));
22
+ if (character == 's' )
23
+ return (ft_putstr_fd ( fd , va_arg (listofarguments , char * ))) ;
24
+ /* if (character == 'p')
25
+ return (função(va_arg(listofarguments, long long unsigned int)));*/
25
26
if (character == 'd' || character == 'i' )
26
- return (função (va_arg(listofarguments, int)));
27
+ return (ft_putint (va_arg (listofarguments , int )));
27
28
if (character == 'u' )
28
- return (função (va_arg(listofarguments, unsigned int)));
29
- if (character == 'o')
29
+ return (ft_putunsint (va_arg (listofarguments , unsigned int ))) ;
30
+ /* if (character == 'o')
30
31
return (função(va_arg(listofarguments, unsigned int)));
31
32
if (character == 'x')
32
33
return (função(va_arg(listofarguments, unsigned int)));
33
34
if (character == 'X')
34
35
return (função(va_arg(listofarguments, unsigned int)));*/
35
36
if (character == '%' )
36
- return (ft_putchar_fd (character , 1 ));
37
+ return (ft_putchar_fd (fd , character ));
37
38
return (0 );
38
39
}
39
40
@@ -42,7 +43,7 @@ int treatment(char character, va_list listofarguments)
42
43
0 ~Left-pads~ the number with zeroes (0) instead of spaces.
43
44
. precision (displays only .X amount of characters)
44
45
# Used with o, x or X specifiers, the value is ~preceded~ with 0, 0x or 0X
45
- respectively for values different than zero.
46
+ respectively for values different from zero.
46
47
Used with e, E and f, it forces the written output to contain a decimal point
47
48
even if no digits would follow.
48
49
By default, if no digits follow, no decimal point is written.
@@ -88,20 +89,22 @@ int ft_printf(const char *fixed, ...)
88
89
{
89
90
int index ;
90
91
int count ;
92
+ int fd ;
91
93
va_list listofarguments ;
92
94
93
95
index = 0 ;
94
96
count = 0 ;
97
+ fd = 1 ;
95
98
va_start (listofarguments , fixed );
96
99
while (fixed [index ] != '\0' )
97
100
{
98
101
if (fixed [index ] == '%' && ft_strchr ("cspdiuoxX%" , fixed [index + 1 ]))
99
102
{
100
- count += ft_putchar_fd ( fixed [index ], 1 );
103
+ count += treatment ( fd , fixed [index + 1 ], listofarguments );
101
104
index ++ ;
102
105
}
103
106
else
104
- count += ft_putchar_fd (fixed [index ], 1 );
107
+ count += ft_putchar_fd (fd , fixed [index ]);
105
108
index ++ ;
106
109
}
107
110
va_end (listofarguments );
0 commit comments