-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf.c
52 lines (47 loc) · 1.58 KB
/
ft_printf.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gantonio <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/27 16:00:54 by gantonio #+# #+# */
/* Updated: 2021/07/17 19:26:21 by gantonio ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
#include <stdio.h>
static int ft_treat_input(va_list args, const char *str)
{
int char_count;
int width;
int i;
char_count = 0;
i = 0;
while (str[i])
{
width = 0;
if (str[i] != '%')
char_count += ft_putchar(str[i]);
else if (str[i] == '%' && str[i + 1])
{
while (ft_isdigit(str[++i]))
width = (width * 10) + (str[i] - 48);
if (ft_istype(str[i]))
char_count += ft_treatment_type(str[i], args, width);
else if (str[i])
char_count += ft_putchar(str[i]);
}
i++;
}
return (char_count);
}
int ft_printf(const char *str, ...)
{
int char_count;
va_list args;
va_start(args, str);
char_count = ft_treat_input(args, str);
va_end(args);
return (char_count);
}