Repository navigation
Expand file tree
/
Copy pathft_printf.c
More file actions
62 lines (56 loc) · 1.9 KB
/
Copy pathft_printf.c
File metadata and controls
62 lines (56 loc) · 1.9 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
62
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marvin <marvin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/09/15 11:17:07 by yaalmoui #+# #+# */
/* Updated: 2026/09/16 21:03:39 by marvin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int check_type(const char *s, va_list args);
int ft_printf(const char *format, ...)
{
va_list args;
int i;
i = 0;
va_start(args, format);
while (*format != '\0')
{
if (*format == '%')
{
format++;
if (ft_strchr("cspdiuxX", *format))
i += check_type(format, args);
else if (*format == '%')
i += print_char('%');
}
else
i += print_char(*format);
format++;
}
va_end(args);
return (i);
}
static int check_type(const char *format, va_list args)
{
int i;
i = 0;
if (*format == 'c')
i += print_char(va_arg(args, int));
else if (*format == 's')
i += print_str(va_arg(args, char *));
else if (*format == 'p')
i += print_pointer(va_arg(args, void *));
else if (*format == 'i' || *format == 'd')
i += print_digit(va_arg(args, int));
else if (*format == 'u')
i += print_digit(va_arg(args, unsigned int));
else if (*format == 'x')
i += print_hex(va_arg(args, unsigned int), 0);
else if (*format == 'X')
i += print_hex(va_arg(args, unsigned int), 1);
return (i);
}