-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
61 lines (56 loc) · 1.82 KB
/
Copy pathft_printf.c
File metadata and controls
61 lines (56 loc) · 1.82 KB
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
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: astoll <astoll@student.42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 08:21:12 by astoll #+# #+# */
/* Updated: 2023/11/15 14:15:56 by astoll ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_convert(va_list args, const char format)
{
int count;
count = 0;
if (format == 'c')
count += ft_putchar(va_arg(args, int));
else if (format == 's')
count += ft_putstr(va_arg(args, char *));
else if (format == 'p')
count += ft_putptr(va_arg(args, uintptr_t));
else if (format == 'd' || format == 'i')
count += ft_putnbr(va_arg(args, int));
else if (format == 'u')
count += ft_putnbr(va_arg(args, unsigned int));
else if (format == 'x' || format == 'X')
count += ft_puthex(va_arg(args, unsigned int), format);
else if (format == '%')
count += ft_putchar('%');
return (count);
}
int ft_printf(const char *format, ...)
{
int i;
int count;
va_list args;
i = 0;
count = 0;
va_start(args, format);
while (format[i] != '\0')
{
if (format[i] == '%')
{
count += ft_convert(args, format[++i]);
i++;
}
else
{
count += ft_putchar(format[i]);
i++;
}
}
va_end(args);
return (count);
}