-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf.c
53 lines (49 loc) · 1.78 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
53
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: msodor <msodor@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/30 18:58:14 by msodor #+# #+# */
/* Updated: 2022/12/22 16:25:29 by msodor ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void format_check(va_list args, const char format, int *counter)
{
if (format == 'c')
ft_putchar(va_arg(args, int), counter);
else if (format == 's')
ft_putstr(va_arg(args, char *), counter);
else if (format == '%')
ft_putchar('%', counter);
else if (format == 'd' || format == 'i')
ft_putnbr(va_arg(args, int), counter);
else if (format == 'u')
ft_putnbr_u(va_arg(args, unsigned int), counter);
else if (format == 'x' || format == 'X')
ft_puthexa(va_arg(args, unsigned int), format, counter);
else if (format == 'p')
ft_putad(va_arg(args, unsigned long), counter);
}
int ft_printf(const char *format, ...)
{
va_list args;
int counter;
counter = 0;
va_start(args, format);
while (*format)
{
if (*format == '%')
{
format++;
format_check(args, *format, &counter);
}
else
ft_putchar(*format, &counter);
format++;
}
va_end(args);
return (counter);
}