Repository navigation
Expand file tree
/
Copy pathft_printf.c
More file actions
59 lines (54 loc) · 1.82 KB
/
Copy pathft_printf.c
File metadata and controls
59 lines (54 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mju-ferr <mju-ferr@student.42lisboa.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/31 10:55:25 by mju-ferr #+# #+# */
/* Updated: 2025/12/31 11:10:20 by mju-ferr ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_handle_format(char format, va_list args)
{
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, unsigned long));
else if (format == 'd' || format == 'i')
count += ft_putnbr(va_arg(args, int));
else if (format == 'u')
count += ft_putnbr_unsigned(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, ...)
{
va_list args;
int count;
int i;
va_start(args, format);
count = 0;
i = 0;
while (format[i])
{
if (format[i] == '%')
{
count += ft_handle_format(format[i + 1], args);
i++;
}
else
count += ft_putchar(format[i]);
i++;
}
va_end(args);
return (count);
}